• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 196
  • Last Modified:

NEWBIE: Null confusion

Dear Experts,

I'm getting a null pointer exception on the following:

while ((line = myClass.getString()) != null)
  {
    // do stuff
  }

Where myClass.getString returns either a String, or null if no String is available.    getString is reading a file, and returning either the next line, or null at EOF.  It's processing the last line, returning to the top of the while loop, and then blowing up.

What could be null here?  Is it "line", or the evaluation of  "(line = myClass.getString()) "?  Does it evaluate "line" BEFORE it assigns it the value of getString?  (Hmmm.)

Thanks,
BrianMc1958
0
BrianMc1958
Asked:
BrianMc1958
  • 2
  • 2
1 Solution
 
CEHJCommented:
It's evaluating line after assignment
0
 
CEHJCommented:
Make sure myClass itself is not null
0
 
BrianMc1958Author Commented:
Hmmmm...  myClass is not null at the BOTTOM of the loop.  I must be doing something extremely newbie-ish here.  Any more ideas?
0
 
BrianMc1958Author Commented:
Sorry.  Idiot...
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now