Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need help with small problems

 
Don Seracino
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I'm pretty new to Java and this is my first semester. Can anybody help me out and tell me what I'm getting wrong here in my "okUserName() method"? I keep trying to work on it but I'm definitely stumped. Also I have an alternate driver class with a main method & a file in the same folder, but everything is perfect there.

*mind the awful indentation I just copy and pasted from my ide.
 
Rajasekar Krishnan
Greenhorn
Posts: 16
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Don,

I don't know whether i understood completly your actual problem or not.

But when i take the code to my IDE, i found two compiler error.

1) writeFile(): no need of handling FileNotFoundException there, because no code throwing this checked exception.

2) okUsername(): should return boolean value. Method should have a default return type irrespective of the return statement which is there in condition scope.

Thanks,
Rajasekar.
 
Greg Brannon
Bartender
Posts: 563
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please, please, please post your code in code tags.

I believe the problem with your okUserName() method is that you have a return statement in an if clause (or in if clauses). When the compiler sees this, it assumes it is possible that the if clauses will never be executed so that a return may never occur, causing the error, method x() must return <something>. A way to correct this is with an else statement:



That way the compiler will see there will always be a value returned.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic