![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Nov 2007
Posts: 1
Rep Power: 0
![]() |
HashTable class
Hi.. I'm writing this HashTable class and I'm not sure what this error is from. I get it when I run this short little test program with more than two calls to put. Any help would be greatly appreciated. Note: The Pair<K,V> class is just basically a K key and V value with getKey and getVal methods.
The Error Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 2, Size: 2 at java.util.ArrayList.RangeCheck(Unknown Source) at java.util.ArrayList.get(Unknown Source) at HashTable.put(HashTable.java:77) at HashTest.main(HashTest.java:9) The Test Program That Produces The Error java Syntax (Toggle Plain Text)
The HashTable class java Syntax (Toggle Plain Text)
|
|
|
|
|
|
#2 |
|
Professional Programmer
![]() Join Date: Sep 2005
Posts: 419
Rep Power: 3
![]() |
Re: HashTable class
Start your debugging quest by realizing that indices in Java are based on a half-open range. In an array of size N, the valid indices are 0 to N - 1.
__________________
Even if the voices aren't real, they have some pretty good ideas. |
|
|
|
|
|
#3 |
|
Hobbyist Programmer
Join Date: May 2006
Location: West Jordan, Utah, United States
Posts: 176
Rep Power: 3
![]() |
Re: HashTable class
Look at <, <=
|
|
|
|
|
|
#4 |
|
11 years old
Join Date: Nov 2007
Posts: 79
Rep Power: 1
![]() |
Re: HashTable class
<= would mean that local variable i would be equal to or less then, which is not what you're aiming for.
What you're aiming for is actually: java Syntax (Toggle Plain Text)
Oh, and Object.equals(Object) return Object == Object, but equals(Object) is overridden in special cases so there is no need for pair.getKey() == key. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| template class | brad sue | C++ | 1 | Mar 25th, 2007 5:46 PM |
| Threading with Hashtable class | ssrun | Java | 1 | Mar 23rd, 2007 6:41 PM |
| URL class | Eric the Red | Java | 5 | Jun 24th, 2006 9:01 PM |
| using classes in another class | ling_wong | C++ | 6 | Jan 23rd, 2006 9:55 PM |
| MFC/OpenGL: problem with 'Document' class | brenda | C++ | 11 | May 23rd, 2005 8:10 PM |