File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes incompatible type Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "incompatible type" Watch "incompatible type" New topic
Author

incompatible type

Matt Hall
Greenhorn

Joined: Feb 28, 2006
Posts: 24
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

Joined: Oct 17, 2005
Posts: 143
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 ]

Stephen Foy - Microsoft Application Development Consultant
vignesh hariharan
Ranch Hand

Joined: Jun 23, 2005
Posts: 77
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.


Regards,
vignesh
Matt Hall
Greenhorn

Joined: Feb 28, 2006
Posts: 24
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

Joined: Jan 17, 2006
Posts: 1296
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.


Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
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

Joined: Feb 28, 2006
Posts: 24
The array IS of type int in this case, sorry for the confusion.
Stephen Foy
Ranch Hand

Joined: Oct 17, 2005
Posts: 143
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

Joined: Feb 28, 2006
Posts: 24
I've managed to sort this out now, thanks for the advice everyone.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: incompatible type