Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.lang.NullPointerException

 
Zack Lock
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20764
30
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That could only be because your "str" variable was null.
 
Zack Lock
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20764
30
Eclipse IDE Firefox Browser MySQL Database
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wow thanks, I feel like such an idiot.....I completely missed my error...Really thanks so much for your help.
 
Campbell Ritchie
Sheriff
Posts: 48424
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I presume you already know how to incorporate the null check in your while condition.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic