Tilted Forum Project Discussion Community

Tilted Forum Project Discussion Community (https://thetfp.com/tfp/)
-   Tilted Technology (https://thetfp.com/tfp/tilted-technology/)
-   -   [JAVA] StringIndexOutOfBoundsException (https://thetfp.com/tfp/tilted-technology/81756-java-stringindexoutofboundsexception.html)

BoltedDown 01-24-2005 11:58 AM

[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]

-Rick

a-j 01-24-2005 03:37 PM

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.

madcow 01-24-2005 05:07 PM

Agreed, at least show a code snippet around the line number the exception is being thrown on, then we can be much more helpful.

noodles 01-24-2005 10:03 PM

ummm...yeah. code.
are you trying to use a string function on an index that doesn't exist?
/me got nothin

AngelicVampire 01-25-2005 01:07 PM

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.

Rangsk 01-27-2005 07:56 PM

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.

ManWithAPlan 02-06-2005 08:55 AM

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

skitz0 02-08-2005 10:29 PM

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 05:29 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2026, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2
© 2002-2012 Tilted Forum Project


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47