views:

47

answers:

2

When my program throws the exception, i'm getting a return value of 7. What exactly does a 7 mean, and where can I get a list of these return values? Or is that just the first line where it happened (although i got a -1 one time)?

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 7
    at DataReader.get(DataReader.java:74)
    at Employees.<init>(Employees.java:48)
    at Main.main(Main.java:7)
+6  A: 

That number is the number you tried to use as the argument of the get call. It is not an error code.

akf
How'd you know i was using a get call? Did you read one of my other questions? hehe
trusktr
The first line of the stacktrace is telling that: `at DataReader.get(DataReader.java:74)`.
BalusC
+5  A: 

It's the array index you were attempting to retrieve.

Your application code is trying to reference beyond the limits of the array. This could be caused by an index larger than the size of the array, or as your first exception indicated, passing in a negative index.

Check those conditions before a potentially risky array access, or at the very least wrap it in a try-catch block so you can recover and move on.

Joe
Cool. thanks! I knew i was outside the array boundaries, but i didn't know that showed the non-existent item i was trying to access. :D Too bad it doesn't say that in the javadocs.
trusktr
It is actually mentioned briefly at least, if not discussed at length: "[The exception] ArrayIndexOutOfBoundsException [is] thrown to indicate that an array has been accessed with an illegal index. The index is either negative or greater than or equal to the size of the array." http://download.oracle.com/javase/1.4.2/docs/api/java/lang/ArrayIndexOutOfBoundsException.html
Joe