Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error code:This method must return a result of type int

 
nicole poirier
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm new to Java and not entirely sure as to why I keep getting the error message "This method must return a result of type int" this is my code:
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it gives that error, then you're using a horrible compiler or IDE. The only error it should give is that you're missing a closing brace } at the end.
 
nicole poirier
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, must have missed the last } when copying it onto here. I'm using eclipse and it won't let me run the file because of this error?
 
Campbell Ritchie
Sheriff
Posts: 48635
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don’t go back to your old post and correct an error which has been pointed out to you. That makes Jeff’s reply look like nonsense.
You should use an indentation convention (one available here, which doesn’t make the serious error of saying you can use tabs) and follow it religiously. You can program it into Eclipse as a project property and then use ctrl‑A‑ctrl‑I to impose indentation.

But you ought not to use an IDE at all if you are a beginner.
 
Campbell Ritchie
Sheriff
Posts: 48635
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you using a counting method on Strings when the String class has lots of methods, one of which does exactly what you want. And faster.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nicole poirier wrote:Sorry, must have missed the last } when copying it onto here. I'm using eclipse and it won't let me run the file because of this error?


Eclipse does not give "This method must return a result of type int" for that code. That code compiles fine. You can't run it because there's no main method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic