适配器中的 NoSuchMethod 与 addAll ?
我有一个像这样声明的 ArrayAdapter 的子类
public class ShoppingCartAdapter extends ArrayAdapter<ShoppingCart> {
,一切都工作正常。现在突然(?)我在运行 2.3.6 的 Nexus S 或运行 2.2 的模拟器上遇到了问题,
12-19 14:33:36.136: ERROR/AndroidRuntime(27326): FATAL EXCEPTION: main
java.lang.NoSuchMethodError: com.somewhere.mobile.fragment.ShoppingCartListFragment$ShoppingCartAdapter.addAll
但它在例如运行 3.2 的 Xoom 上仍然可以正常工作。
我没有重写 super addAll 方法,因为它在某些设备上工作,所以我不知道下一步该看哪里。有什么提示吗?
更新:
我替换了adapter.addAll(newCarts)
for (ShoppingCart cart : newCarts) {
adapter.add(cart);
}
并有效。我认为它与泛型有关,但尚未确定。
I have a subclass of an ArrayAdapter declared like this
public class ShoppingCartAdapter extends ArrayAdapter<ShoppingCart> {
and everything has been working fine. Now suddenly(?) I have problems with this on my Nexus S running 2.3.6 or an emulator with 2.2 throwing
12-19 14:33:36.136: ERROR/AndroidRuntime(27326): FATAL EXCEPTION: main
java.lang.NoSuchMethodError: com.somewhere.mobile.fragment.ShoppingCartListFragment$ShoppingCartAdapter.addAll
however it still works just fine on e.g. my Xoom with 3.2.
I am not overriding the super addAll methods and since it works on some device I am not sure where to look next. Any hints?
UPDATE:
I replaced adapter.addAll(newCarts) with
for (ShoppingCart cart : newCarts) {
adapter.add(cart);
}
and that works. I assume it has something to do with generics but have been unable to nail it down yet.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从 API 11 (Android 3.0) 开始添加。这里的
has been added starting from API 11 (Android 3.0). Here the doc.
addAll(...) 在较低的 API 级别中不可用。它是在 API 11 及更高版本中添加的。因此,使用 add(...) 来解决这个问题,如下所示
,而不是
addAll(...) is not available in lower API levels. Its added in API 11 and above. So use add(...) to fix this issue as follows
instead of