This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "StringIndexOutOfBounds Exception" Watch "StringIndexOutOfBounds Exception" New topic
Author

StringIndexOutOfBounds Exception

Charmaine Gatling
Greenhorn

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
Sheriff

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]
 
Don't get me started about those stupid light bulbs.
 
subject: StringIndexOutOfBounds Exception
 
Similar Threads
Date / Time problems
Need help with Substring
pet peeves 2
substring question
subString