It's not a secret anymore!*
The moose likes Java in General and the fly likes java.lang.NullPointerException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "java.lang.NullPointerException" Watch "java.lang.NullPointerException" New topic
Author

java.lang.NullPointerException

Zack Lock
Greenhorn

Joined: Feb 15, 2011
Posts: 5
I'm getting an error "Exception in thread "main" java.lang.NullPointerException" at line 19. and I have no idea why. The program is to read the contents of a text file and write each line into an array of objects.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18709
    
    8

That could only be because your "str" variable was null.
Zack Lock
Greenhorn

Joined: Feb 15, 2011
Posts: 5
any suggestions for fixing that without getting too in depth? This project contains several different files and the "Accounts.txt" file reads as follows.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18709
    
    8

Without getting too in-depth, I would suggest modifying your "while" condition so that it doesn't allow the loop to be executed when str is null.
Zack Lock
Greenhorn

Joined: Feb 15, 2011
Posts: 5
wow thanks, I feel like such an idiot.....I completely missed my error...Really thanks so much for your help.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
Welcome to the Ranch

I presume you already know how to incorporate the null check in your while condition.
 
jQuery in Action, 2nd edition
 
subject: java.lang.NullPointerException