• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Eclipse - public static int error  RSS feed

 
Lennart van Ham
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

I've got a problem in Eclipse. The below code is a part of my program, used for (re)starting a new game.
The 'public static int' statement gives the error 'This method must return a result of type int'..
Of course I get that, but isn't that already the case?? Some help would be great.




Sorry I'm new to this, couldn't get tabs in the code..
 
Paul Clapham
Sheriff
Posts: 22844
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lennart van Ham wrote:'This method must return a result of type int'


In other words you need some return statements somewhere in that code which return the value. You don't have any.

By the way I added the code tags to your post. Next time you post you'll see a "Code" button above the box you're posting in, so read UseCodeTags to find out how to do that. I'm also going to move your question to the Beginning Java forum where it would be more suitable than Servlets.
 
Lennart van Ham
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Allright thanks for that.

Allright, but don't I have those already with return 0 and return 1? Or should I change public static int to another kind of statement or something?
Really have thought everything over but don't have a clue how to let this work.
 
Paul Clapham
Sheriff
Posts: 22844
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right, you do sometimes return a value. But sometimes you don't return a value -- at least as far as the compiler can tell -- and that's the problem. For example after your while-loop terminates and processing continues after line 20, there's no return statement. (Telling me that that will never happen will be pointless; I can see that but the compiler can't.)

 
Lennart van Ham
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ahhh ofcourse.. Thank you very much!
 
Paul Clapham
Sheriff
Posts: 22844
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way... shouldn't that method be returning a boolean value which is true if the user wants to play again and false if not? Why is it returning 0 or 1?
 
Lennart van Ham
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could be, but here 1 activates the game, 0 says 'goodbye'.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!