Results 1 to 5 of 5
- 09-22-2009, 03:58 AM #1
Member
- Join Date
- Sep 2009
- Posts
- 3
- Rep Power
- 0
-
I am no expert in things like this, far from it, but shouldn't the object held by your list implement the Comparable interface? I think that you declare this something like so:
(I used List here rather than ListInterface since I have no idea what ListInterface is).Java Code:public class OrderedList<E extends Comparable<E>> implements List<E>, Iterable<E> { //....
- 09-22-2009, 04:27 AM #3
Member
- Join Date
- Sep 2009
- Posts
- 3
- Rep Power
- 0
Yes, but for this project I was given the test program and was told not to change it. implementing the Comparable interface causes an error in the test program.
Bound mismatch: The type T is not a valid substitute for the bounded parameter <E extends Comparable<E>> of the type OrderedList<E>
- 09-22-2009, 05:28 AM #4
Member
- Join Date
- Sep 2009
- Posts
- 3
- Rep Power
- 0
I think that I have solved the problem. But now I can't get my add method to work. Here is what I am using:
when I run the program it adds the first item to the list then it gives me the following error:Java Code:
Exception in thread "main" java.lang.NullPointerException
at java.lang.Character.compareTo(Unknown Source)
at TestOrderedList$1.compare(TestOrderedList.java:24)
at TestOrderedList$1.compare(TestOrderedList.java:1)
at OrderedList.add(OrderedList.java:34)
at TestOrderedList.test0(TestOrderedList.java:30)
at TestOrderedList.main(TestOrderedList.java:7)Last edited by repairmanjack; 09-22-2009 at 07:50 AM.
- 09-22-2009, 06:41 AM #5
Member
- Join Date
- Jun 2008
- Posts
- 56
- Rep Power
- 0
Incorrect code:
1. add is ALWAYS true, it never changes to false.PHP Code:for (int i = 0; add == true;i++) if (compare(newEntry,list[i])>=0){ list[size] = newEntry; add = true;} size++; return true;
2. list[size] = newEntry;. YOu should to insert new element in ith position.Try Controls4J - Advanced Swing Components.
Similar Threads
-
generic types
By jon80 in forum New To JavaReplies: 6Last Post: 06-12-2009, 10:29 PM -
Comparing two data types in order to store in array
By gwithey in forum New To JavaReplies: 3Last Post: 05-01-2009, 10:27 AM -
Generic methods
By andre1011 in forum Advanced JavaReplies: 7Last Post: 02-25-2009, 02:17 PM -
Can generic types implement an interface?
By jdgallag in forum New To JavaReplies: 3Last Post: 10-30-2008, 04:07 AM -
Comparing types, integer with null
By Felissa in forum New To JavaReplies: 1Last Post: 07-05-2007, 06:32 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks