Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 198
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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