Solved

NEWBIE: Null confusion

Posted on 2006-11-14
4
190 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 125 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jboss 7.1 start up error 1 60
sql import cannot be resolved jsp 3 74
JAVA API design with micro service cloud in mind 1 76
batch vs regular insert in spring DAO 2 20
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

735 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