File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Need help with small problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Need help with small problems" Watch "Need help with small problems" New topic

Need help with small problems

Don Seracino

Joined: Mar 18, 2011
Posts: 1
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

Joined: Feb 27, 2008
Posts: 16

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.

Greg Brannon

Joined: Oct 24, 2010
Posts: 563
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.

Always learning Java, currently using Eclipse on Fedora.
Linux user#: 501795
I agree. Here's the link:
subject: Need help with small problems
It's not a secret anymore!