![]() |
[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 |
I'm not sure what you want. Are you wondering what the error means? Where in your program caused the error? How to fix the problem?
Please be less vague. |
Agreed, at least show a code snippet around the line number the exception is being thrown on, then we can be much more helpful.
|
ummm...yeah. code.
are you trying to use a string function on an index that doesn't exist? /me got nothin |
How long is the string? Strings can be created as an array, if you are trying to work beyond the end of it then you will create errors iirc.
|
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.
|
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 |
It's out of bounds because it's null, don't focus on the exception, focus on why that object is null.
|
All times are GMT -8. The time now is 09:25 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2
© 2002-2012 Tilted Forum Project