Android的SDK。字符串索引出界异常 [英] Android SDK. String index out of bound exception
问题描述
我终于有我的应用程序处理的地图和点(阵列)。快速的问题:我有一个致命异常子()
,一个stringIndexOutOfBoundException
I FINALLY have the map and points(arrays) working for my app. Quick question: I have a fatal exception with substring()
, a "stringIndexOutOfBoundException"
在一般情况下,什么是指?
In general, what is that referring to?
这是我使用去过去字符串的结尾子()
?
An I going past the end of a string using substring()
?
谢谢,
推荐答案
是的,你要过去你的字符串边界的结束一般。
Yes, you're going past the end of your strings bounds generally.
借助的Java API ,甚至会告诉你这样...
The Java API even tells you so...
IndexOutOfBoundsException异常。 - 如果beginIndex大于这个字符串对象的长度负或更大
IndexOutOfBoundsException - if beginIndex is negative or larger than the length of this String object.
您应该习惯使用的API。它告诉你一个方法抛出异常是什么,以及为什么。
You should get used to using the API. It tells you what exceptions a method throws and why.
尝试尝试字串前面打印字符串长度和值。这会帮助你看到的问题。
Try printing the Strings length and value before attempting substring. That'll help you see the problem.
例如...
String testing = "Hello StackOverflow";
System.out.println("Length of testing = " + testing.length);
System.out.println("Value of testing = " + testing);
testing.substring(1,2);
这篇关于Android的SDK。字符串索引出界异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!