01-24-2005, 11:58 AM | #1 (permalink) |
Crazy
|
[JAVA] StringIndexOutOfBoundsException
I'm still pretty new to Java. Right now i'm working on a POS program. Eclipse threw this error at me.
Code:
java.lang.StringIndexOutOfBoundsException: String index out of range: 34 ProductCatalog[productSpecifications = null] |
01-27-2005, 07:56 PM | #6 (permalink) |
Crazy
Location: San Diego, CA
|
You're accessing character 34 of a string with length less than 35 (Java arrays are 0-based). That's what the error is telling you. Without code I can't help you any more than that.
__________________
"Don't believe everything you read on the internet. Except this. Well, including this, I suppose." -- Douglas Adams |
02-06-2005, 08:55 AM | #7 (permalink) |
Addict
Location: M[ass]achusetts
|
ProductCatalog[productSpecifications = null] <-- that is your code right?
if so, why are you setting productSpecifications to null in the indexer? otherwise, outofbounds usually means something like this... string[] mystringarray = new string[3] ^^ that array will have 4 valid objects... mystringarray[0] mystringarray[1] mystringarray[2] mystringarray[3] but if you do mystringarray[4], that's out of bounds. so you just have to make sure that the variable you use to retrieve an index of an array is within the bounds of the array. to see how big an array is use the 'length' variable Code:
int length = mystringarray.length
__________________
In the end we are but wisps |
Tags |
java |
|
|