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.
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.
Joined: Oct 13, 2005
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.
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.