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)
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.