Solved

NEWBIE: Null confusion

Posted on 2006-11-14
4
192 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

627 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