• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

NullPointerException at Java.util.StringTokenizer

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,

I am new to this forum seeking some help.

Here's the code :




Here's the output:




This quite working. At the bottom of the output you can see the error occurred.

How can I fix it?


Any help very much appreciated.

Thanks,
Ben

 
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Print out the value of list after line 35 and see if it is always what you are expecting - take special note of the first and last time through the loop.
 
Ben Owats
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Stuart for the reply...

Is this what you mean?



If so, still the problem occurred. Their is a data from text file showing in the output. I don't if that's what you mean of "Print out the value of list after line 35". I'm not good in looping...

Here's the output :



 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ben. Welcome to the Ranch!

Think about the order you're doing things in that loop. You check if list is null, then you get the next token, then you create the employee profile. So when list is finally null...you still carry on. Your second version confirms this - you print out null. You need to stop as soon as that happens.
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ben Owats wrote:If so, still the problem occurred.


That wasn't how to fix it. That was how to debug it. Look at the first result that you print out in the EmployeeProfile method. Is that the data from the first record in the input file or the second one ?
 
Greenhorn
Posts: 26
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
At line 33 you may try
while ((list = br.readLine()) != null) {
EmployeeProfile(list);
}

While we use br.readLine it will be reading the next line so the list will be null.
 
Ben Owats
Greenhorn
Posts: 3
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, Its working now....

Thank you very much Jo!

Thank you for the reply guys!

Cheer!


 
I claim this furniture in the name of The Ottoman Empire! You can keep this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic