Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

NEWBIE: Null confusion

Posted on 2006-11-14
4
Medium Priority
?
195 Views
Last Modified: 2010-03-31
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
Comment
Question by:BrianMc1958
  • 2
  • 2
4 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 17941086
It's evaluating line after assignment
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 17941136
Make sure myClass itself is not null
0
 

Author Comment

by:BrianMc1958
ID: 17941209
Hmmmm...  myClass is not null at the BOTTOM of the loop.  I must be doing something extremely newbie-ish here.  Any more ideas?
0
 

Author Comment

by:BrianMc1958
ID: 17941287
Sorry.  Idiot...
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question