This week's book giveaway is in the OCAJP forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff 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 OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic
Author

TreeSet Problem

Nathan Doe
Greenhorn

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
author
Sheriff

Joined: Sep 28, 2004
Posts: 19235
    
  41

Seems to be a duplicate topic...

http://www.coderanch.com/t/466947/Java-General/java/Implementing-Comparable-Interface-with-TreeSets

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.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: TreeSet Problem