• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

Run Time Error  RSS feed

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 . . .
 
lowercase baba
Bartender
Posts: 12628
50
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 502
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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,

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!