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.
addAll(...)
has been added starting from API 11 (Android 3.0). Here the doc.
addAll(...) is not available in lower API levels. Its added in API 11 and above. So use add(...) to fix this issue as follows
for (int i = 0; i < contents.size(); i++) { adapter.add(contents.get(i)); }
instead of
//adapter.addAll(contents); //do not use addAll(...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With