Forums Register Login

StringIndexOutOfBounds Exception

+Pie Number of slices to send: Send
In a program that searches multiples strings for a certain set of characters (substring) and returns the index of that substring, I get this StringOutOfBoundException. I'm using String.index() and it works for about 25 iterations then I get this error. What am I not doing?
+Pie Number of slices to send: Send
It would help tremendously if you would post a portion of your code. Thanks!
+Pie Number of slices to send: Send
I'll guess that the exception that you were actually getting was the StringIndexOutOfBoundsException. Taking a look at the documentation for StringIndexOutOfBoundsException we find a simple explanation for when this exception is thrown:

Thrown by String methods to indicate that an index is either negative or greater than the size of the string. For some methods such as the charAt method, this exception also is thrown when the index is equal to the size of the string.

Are you sure that you aren't trying to search a String beyond it's length? Are you getting any ideas?
A wop bop a lu bop a womp bam boom! Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1792 times.
Similar Threads
subString
Need help with Substring
Date / Time problems
pet peeves 2
substring question
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 00:11:49.