| Author |
java.lang.StringIndexOutOfBoundsException: String index out of range: -2
|
Farakh khan
Ranch Hand
Joined: Mar 22, 2008
Posts: 672
|
|
Hello,
This is my remove comma method
Line 6 of the code is throwing this error
Thanks & best regards
|
 |
Sankar Mitra
Greenhorn
Joined: Oct 24, 2011
Posts: 4
|
|
|
It is possible only when the String str does not contain any character.Since it is empty its length is 0 and you are trying to go to its -2 position which is out of bounds.
|
 |
Farakh khan
Ranch Hand
Joined: Mar 22, 2008
Posts: 672
|
|
Thanks for your reply.
How can I fix it?
|
 |
Claudiu Chelemen
Ranch Hand
Joined: Mar 25, 2011
Posts: 67
|
|
Try checking the string's length before calling substring.
If it is long enough, call the substring, otherwise leave it as it is.
Claudiu
|
 |
Farakh khan
Ranch Hand
Joined: Mar 22, 2008
Posts: 672
|
|
Thanks from the bottom of my heart. Now its working fine
Best regards
|
 |
Harsha Smith
Ranch Hand
Joined: Jul 18, 2011
Posts: 287
|
|
|
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32830
|
|
Never use ==true or ==false. It should be
... if (isCat) ...
|
 |
Farakh khan
Ranch Hand
Joined: Mar 22, 2008
Posts: 672
|
|
|
thanks for the tip
|
 |
 |
|
|
subject: java.lang.StringIndexOutOfBoundsException: String index out of range: -2
|
|
|