Follow Us
  • Register
Errorbase is a collaborative writing project, that aims to build the largest trouble-shooting guide about all kinds of error messages.


+1 vote

This exception is thrown in java when the index is higher than the size of the string. Ex:
String str = "abcd";

The above example will throw StringIndexOutOfBoundsException, because the string contains only 4 character elements and the index is 5.

requested by (170k points)
edited by

1 Solution

+1 vote

The thrown exception shows the line number in which the problem has occured. The exception thrown for the above example is like this:
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 5
at java.lang.String.charAt(Unknown Source)
at SomePackage.SomeClass.main(

For this example the problem has occured in line 11. By this way you can reach the variable which created the problem. After finding the variable, debug the code for that variable.

solved by (170k points)
edited by