【发布时间】:2014-04-06 06:48:21
【问题描述】:
我一直在解析 html 以获取特定链接的标题。我可以将此字符串添加到字符串数组,但我想从驻留在我的 strings.xml 资源中的字符串数组中添加一个字符串。
int i = 1;
String time = null;
for (Element title : rels) {
time = getResources().getStringArray(R.array.times)[i];
titleArray.add(time + title.attr("title"));
i++;
}
这是我的字符串资源:
<string-array name="times">
<item name="1">12:00 am</item>
<item name="2">12:30 am</item>
<item name="3">1:00 am</item>
<item name="4">1:30 am</item>
<item name="5">2:00 am</item>
</string-array>
我在 LogCat 中收到此错误:
04-06 01:44:08.837: E/AndroidRuntime(30938): Caused by: java.lang.ArrayIndexOutOfBoundsException: length=48; index=48
我在这个字符串数组中有 48 个字符串,这与我从 html 解析的字符串数量完全相同。我不确定为什么我的应用程序会强制关闭。有人知道吗?
【问题讨论】:
-
你试过从 int i = 0; 开始吗? ?
标签: java android xml arrays string