Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NoSuchMethod with addAll in Adapter?

Tags:

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.

like image 978
Manfred Moser Avatar asked Dec 19 '11 23:12

Manfred Moser


2 Answers

addAll(...) 

has been added starting from API 11 (Android 3.0). Here the doc.

like image 64
gwvatieri Avatar answered Sep 28 '22 02:09

gwvatieri


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(...) 
like image 43
Nauman Zubair Avatar answered Sep 28 '22 03:09

Nauman Zubair