File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes StringIndexOutOfBounds Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "StringIndexOutOfBounds Exception" Watch "StringIndexOutOfBounds Exception" New topic

StringIndexOutOfBounds Exception

Charmaine Gatling

Joined: Jan 10, 2002
Posts: 11
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?
Tom Purl
Ranch Hand

Joined: May 24, 2002
Posts: 104
It would help tremendously if you would post a portion of your code. Thanks!

Tom Purl<br />SCJP 1.4
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
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?

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
I agree. Here's the link:
subject: StringIndexOutOfBounds Exception
It's not a secret anymore!