exception in java, string index out of range: -1

how to solve java.lang.stringindexoutofboundsexception: string index out of range: -1
how to solve string index out of range: -1
java.lang.stringindexoutofboundsexception: string index out of range: -1 stackoverflow
string index out of range: -1 oracle
exception in thread "main" java.lang.stringindexoutofboundsexception: string index out of range: -1
string index out of range: -1 in selenium
talend java.lang.stringindexoutofboundsexception: string index out of range: -1
java.lang.stringindexoutofboundsexception: string index out of range: -1 scala

I am trying to remove the last character on my output but this error shows me, java.lang.StringIndexOutOfBoundsException: String index out of range: -1

my code

the error


If you are trying to remove the last character in the StringBuilder/StringBuffer, you do it like this:

if (output.length() > 0) {
    output.setLength(output.length() - 1);
}

PS: I downvoted you because you are not supposed to copy your code into the post, not upload it as a screenshot.

Java substring: 'string index out of range', What does it mean when string index is out of range? Handle java.lang.StringIndexOutOfBoundsException: String index out of range : 1. Check the string bounds before accessing its chars. 2. Use try catch.


I have no idea what your code is trying to accomplish, however it's likely what is happening is output is empty, and you're trying to access the -1th character for it, which can't be done.

To fix what you've done, try and implement the following.

On line 59, update the if statement to read:

if (rs.next() == false && output.ToString() != "")

Python error: string index out of range python, Hi Team, I am getting error java.lang.StringIndexOutOfBoundsException: String index out of range: -40 when i am clicking on particular Workset  I am trying to read some words from TXT file and I am getting this error: java.lang.StringIndexOutOfBoundsException: String index out of range: -1 . I have no idea


You need to check the length of output before the split, the error is maybe the string length is zero.

StringIndexOutOfBoundsException (Java Platform SE 7 ), Project fails to build with codegen exception: java.lang.​StringIndexOutOfBoundsException: String index out of range: -6 (Doc ID 1327400.1). Exception in thread main java.lang.StringIndexOutOfBoundsException: String index out of range: 60. For the length of the string, I am trying to do something like this.


LGDJAVA: String index out of range: 9131 Exception in thread "Thread-1740" java.lang.StringIndexOutOfBoundsException: String index out of  As per my above comment, it will be easuer to use the String split method. Of course input can be replaced with text from the file, and use of expectedResult and testing that the output equals that is purely optional


context with path [] threw exception java.lang.​StringIndexOutOfBoundsException: String index out of range: -14 at java.lang.​String.substring(String.java:1967)  The String class in Java provides various methods to manipulate Strings. You can find the character at a particular index using the charAt() method of this class. This method accepts an integer value specifying the index of theStringand returns the character in the String at the specified index. In the following Java program, we are creating a


evaluateString for preloading Java Objects #270 StringIndexOutOfBoundsException: String index out of range: 3 around it, but now of course the usage of direct packages wont work anymore (throws same exception!) When using the Java substring() method, a subset of the character sequence can be extracted from a string. The substring index must be any value from 0 to the length of a string.