This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Run Time Error Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Run Time Error" Watch "Run Time Error" New topic
Author

Run Time Error

Frances Hollis
Greenhorn

Joined: Sep 02, 2006
Posts: 17
OK I got my code to compile but I am getting RTE. I would appreciate if someone could give me some help. I am probably overlooking something simple because I do not have a good understanding of using the methods for Collections yet. I am still learning how to read the APIs.




Exception in thread "main" java.lang.NullPointerException
at java.util.TreeMap.compare(TreeMap.java:1093)
at java.util.TreeMap.getEntry(TreeMap.java:347)
at java.util.TreeMap.containsKey(TreeMap.java:204)
at java.util.TreeSet.contains(TreeSet.java:196)
at Roster.find(Roster.java:31)
at RosterTest.doFind(RosterTest.java:69)
at RosterTest.main(RosterTest.java:24)
Press any key to continue . . .
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 9946
    
    6

a NullPointerExeption comes when you have a reference to an object, but no actual object has been created.

i'm guessing your trying to read something out of your Roster before you put something into it?


Never ascribe to malice that which can be adequately explained by stupidity.
Prabhu Venkatachalam
Ranch Hand

Joined: Nov 16, 2005
Posts: 502



In your Student class, you are implementing compareTo method from Comparable interface. In that method, without checking whether supplied object is null or not, you are calling the method.

Try changing this like below,



Prabhu Venkatachalam<br />SCJP 1.4,SCWCD 1.4<br />prabhu.venkatachalam@gmail.com
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Run Time Error
 
Similar Threads
Exception in thread "main" java.lang.NullPointerException
question about using boolean to check a condition of an object?
Method Hash
Java Array search and print
cannot resolve symbol