• 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

dereferenced errors.....ugh

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just to let you know I have been programming Java for 4 weeks........
Now that you have stoped cringing I have a problem that I am sure everyone but me knows how to fix.
I am trying an IF loop to input employee.getName in the program file and save that and other information into a EmployeeRecord.java file.
Here is the if loop;
if ( ( employee.getName() ).equalsIgnoreCase( STOP ) )
{
break; //Exits Main Loop
}// End IF
That is supposed to have the user be in a loop inputing information until they enter stop.....

Yea, so I am clueless and very much so noobtastic, some one guide me with their elite Java Force....PLEASE!
 
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the exception or specific problem you are encountering? I couldn't determine that from the post.



Is dangerous because employee.getName() may be NULL. Calling .equalsIgnoreCase() on a NULL reference will result in a NullPointerException. (I'm assuming that you've already checked for a NULL employee reference.)

To eliminate the possiblity of a NPE, you'll need to add a check for employee.getName() == NULL before the if statement. Or, what I do is reverse the comparision:



STOP will not be NULL because you defined it as a final static String and initialized it, right?
 
Edward Knight
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I used your suggestion of inverting the STOP in the .equalsIgnoreCase and then changed from void to Static in the other file. It has taken my error away, thank you sooo much . I really appreciate the help.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic