This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes TreeSet Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic

TreeSet Problem

Nathan Doe

Joined: Oct 17, 2009
Posts: 24
In a project i'm working on I have to take a census .txt file containing names and put it into a "NameRank" (which holds the name, and information about the national ranking of the name) after I put the file into an Array of NameRanks. The next part I have to create 5 data structures - ArrayList, HashSet, LinkedList, TreeSet, and Vector and put the info. from the NameRank Array into each and bench mark the time it takes to complete the whole process. I wrote my code and it all works except when I try to add something to the TreeSet that i have created using:

when it gets to adding the file from the array I get this error:

The line that it is generating this exception is in this loop:

For every other data structure it works when this is commented out.

- Nathan
Henry Wong

Joined: Sep 28, 2004
Posts: 18503

Seems to be a duplicate topic...

And it looks like that EFH gave you the exact instructions on how to hunt down the NPE. What is it that you don't understand? But post in that topic, as I am closing this one.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
It is sorta covered in the JavaRanch Style Guide.
subject: TreeSet Problem
Similar Threads
Java noob -- sentinel-controlled while loop
getting the index of the closest value in an array that is sorted in reverse order
Implementing Comparable Interface with TreeSets
Separate GUI Code from Back End Code