Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Null Pointer Exception in set class insertion  RSS feed

 
Tom Brodhead
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm receiving a null pointer exception when I try to perform a simple insertion into a list.

First, here are abbreviated listings of the 3 classes my main class references:




Here is the code I'm writing. I'm constrained to make mySet of type List, and then initialize it to type SList in the constructor of Set(). The problem is that I can't seem to use the insertFront() method except in the constructor:



Many thanks for your help,
~~Tom
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your Set class,

should be
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And you probably want the variables of the Set class to be non-static.
 
Tom Brodhead
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!

I'm a bit confused about the Comparable item type that I'm using for the insert() method. Do I not have to implement Comparable in the main Set class? If so, how would I compose the compareTo() method that's apparently required for the implementation? By that I mean I don't understand how I would perform greater-than/less-than comparisons on Set objects themselves; I can only imagine comparing the items within the various SListNodes...

Many thanks
~~Tom
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This last question about Comparable is being discussed here..
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!