📜  java.lang.stringindexoutofboundsexception:字符串索引超出范围:10 - 无论代码示例

📅  最后修改于: 2022-03-11 14:56:33.850000             🧑  作者: Mango

代码示例1
The type of exception thrown is a StringIndexOutOfBoundsException. Anytime you get an IndexOutOfBoundsException (or any type thereof) it means that you are trying to access an index in an array that doesn't exist. By calling the substring method, you are dividing the string in a character array, and selecting characters A to B (In your case 0 to 1). If character 1 doesn't exist, and yet you try to access it, it will throw this error.

The reason you are getting this error is therefore that you are trying to execute a substring(0,1) on a String with less than 1 character, aka an empty string or even a null string maybe.