【发布时间】:2013-03-27 02:56:12
【问题描述】:
我一直在尝试使用ArrayList.add,当我只输入.add("some data") 时它工作正常,当我尝试分配 id 时 - .add(1, "some data"); 我在尝试运行应用程序时不断收到错误 - “应用程序MobileApp(process com.example.mobileapp) 已意外停止。请重试。”。
这是我正在运行的下一个代码:
List<String> log = new ArrayList<String>();
log.add(1, "some data");
这很好用:
List<String> log = new ArrayList<String>();
log.add("some data");
我想由此实现的目标:
-
ListView将有项目列表,每个项目都有特定的“id”。 - 点击后,该“id”将被拾取,用户将被移动到不同的布局,其中在带有选定“id”的项目上显示更多信息。
【问题讨论】:
-
你能粘贴你的 LogCat 输出吗?
-
from doc
Throws: IndexOutOfBoundsException - if the index is out of range (index < 0 || index > size())size() is zero your index is 1 ... -
如果你想要
each item would have specific "id",你应该考虑Map<Integer, String> -
请学习如何查看logcat的输出。你会看到有一个 ArrayIndexOutOfBoundsException 被抛出。
标签: android listview arraylist