String index out of range: -4 Error parsing

This error is reported because a StringIndexOutOfBoundsException is thrown during the operation on the string

The following methods may throw the above exception:

String.substring()

String.charAt()

String.codePointAt()

String.codePointBefore()

String.subSequence()

String.getChars()

String.getBytes()

Cause Analysis:

This error means that the index of the string is out of bounds

It is generally caused when operating on strings, for example

String str = "123"; //The length of the string is 3
str.substring(0,str.length()-4); //It will report an error String index out of range: -4

おすすめ

転載: blog.csdn.net/m0_63270506/article/details/127093474