• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Trouble finding NullPointerException

 
Jonathan Elens
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to write a program that reads words from a text file and adds the words with a certain character length to a set. But when I try to run it, I get a NullPointerException and I am stuck. Any help would be greatly appreciated.

 
Ivan Jozsef Balazs
Rancher
Posts: 972
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A stack trace reveals the line where the Exception was thrown.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

We can only help with more details. For example, where does the Exception occur? Please post the entire stack trace (using copy‑and‑paste).
I can see some design I am not happy with. Your class should have a constructor and all the fields should be initialised in the constructor (or, for static fields, an initialiser). I would put the reading details in a method in the class, not the main method. Then you can shorten the main method to its ideal length: one statement.

Are you really calling the readFile() method from the main method? Does that actually compile? It is necessary for us to see the real code if we are to help.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is LinkedSet? I can’t find it in the API. You really do have to post the real code, or we can’t help. Please copy and paste it into your next post.
 
Matthew Brown
Bartender
Posts: 4566
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If that's the actual code I'm surprised it gets as far as a NullPointerException. You don't have a valid main method - it isn't static. And if it was static, it wouldn't compile without further changes.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic