I am trying to add
String items to a sorted array list, using compareTo to find the proper position for each item.
This is the runtime error I get when I run ListPop.java with sortedAdd() defined with a String, instead of Object, in the argument list.
Exception in
thread "main" java.lang.NullPointerException
at java.lang.String.compareTo(String.java:789)
at java.lang.String.compareTo(String.java:825)
at SortedList.sortedAdd(SortedList.java:41)
at ListPop.main(ListPop.java:17)
When I try to define sortedAdd() with an Object, instead of a String, in the argument list I get this error message when I compile SortedList.java
SortedList.java:41: cannot resolve symbol
symbol : method compareTo (java.lang.Object)
location: class java.lang.Object
while(item.compareTo((Object)arr[pos]) <= 0) {
1 error
Here is SortedList.java
Here is FullName.java, which implements compareTo()
Here is ListPop.java, which attempts to populate the array.
It should put the first item in the array here
so why is it giving me the NullPointerException for arr[]?
New ones should be added when the while loop in sortedAdd() finishes, right?
Thanks!
[ October 09, 2002: Message edited by: Doug Wolfinger ]
[ October 09, 2002: Message edited by: Doug Wolfinger ]