• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need help with small problems

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 16
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
I will suppress my every urge. But not this shameless plug:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic