File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

incompatible type

 
Matt Hall
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public String setHighcard(){

Random RNum = new Random();
int start;
start = 1 + RNum.nextInt(12);
Highcard = DHand1[start];
return(Highcard);
}

this produces an incompatible type message from the compiler, what data type should be used so that the result can still be passed to another class (i.e. void wont work as cant be accessed from outside the class).
 
Stephen Foy
Ranch Hand
Posts: 143
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your returning an integer in a string method, or change method type to int or you could send the result to a variable inside the class.
[ April 02, 2006: Message edited by: Stephen Foy ]
 
vignesh hariharan
Ranch Hand
Posts: 77
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the return type of the given method is String and the value which u have returned is an int. so there arises a non-compatibility issue.
soln.
change the return type String to int

i hope you got it cleared.
 
Matt Hall
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
setting the return type to int by doing

public int setHighcard(){

Random RNum = new Random();
int start;
start = 1 + RNum.nextInt(12);
Highcard = DHand1[start];
return(Highcard);
}

produces 2 "missing return statement" errors, any ideas?
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't what you guys are seeing in the OP's post that lead you to believe that an int is being returned. For all we know DHand could be an array of any type.
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Garrett Rowe:
I don't what you guys are seeing in the OP's post that lead you to believe that an int is being returned. For all we know DHand could be an array of any type.
Nevermind, I see the other post now.
 
Matt Hall
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The array IS of type int in this case, sorry for the confusion.
 
Stephen Foy
Ranch Hand
Posts: 143
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is highcard a string? and your assigning it an int value from your int array. Also highcard isnt declared in the method, your changing its value outwith the method, so i dont think you need to return it.

Who said void methods cant be accessed outwith the class?
[ April 02, 2006: Message edited by: Stephen Foy ]
 
Matt Hall
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've managed to sort this out now, thanks for the advice everyone.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic