wood burning stoves*
The moose likes Java in General and the fly likes String index out of range - what does this mean? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "String index out of range - what does this mean?" Watch "String index out of range - what does this mean?" New topic
Author

String index out of range - what does this mean?

rita mistry
Greenhorn

Joined: Dec 04, 2001
Posts: 27
Hi all,
What does the following error mean? And why does it occur?
java.lang.StringIndexOutOfBoundsException:
String index out of range: 4.
Thanks in advance
Regards,
rita
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
You are trying to access a point in the string that does not exist. Say a string has 3 characters and you try to access position 6. You would get that error.
Jax Laakso
Greenhorn

Joined: Dec 07, 2001
Posts: 23
You will get that error if you're using the charAt() method and other methods. According to java.sun.com's API documentation you get that error when:

public class StringIndexOutOfBoundsException
extends IndexOutOfBoundsException
Thrown by the charAt method in class String and by other String methods to indicate that an index is either negative or greater than or equal to the size of the string.

For example:

The above code will generate the StringIndexOutOfBounds exception because there isn't 100 characters in string test.
Jax
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String index out of range - what does this mean?