my dog learned polymorphism*
The moose likes Java in General and the fly likes Trouble finding NullPointerException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Trouble finding NullPointerException" Watch "Trouble finding NullPointerException" New topic
Author

Trouble finding NullPointerException

Jonathan Elens
Greenhorn

Joined: Sep 21, 2012
Posts: 1
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

Joined: May 22, 2012
Posts: 867
    
    5
A stack trace reveals the line where the Exception was thrown.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37992
    
  22
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

Joined: Oct 13, 2005
Posts: 37992
    
  22
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

Joined: Apr 06, 2010
Posts: 4343
    
    8

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.
 
wood burning stoves
 
subject: Trouble finding NullPointerException
 
Similar Threads
counting letters in a substring
FTP Socket Programming
I am supposed to call two service classes from one client(main) class?
I am supposed to call two service classes from one client(main) class?
anagram finder help