here are my items
public ArrayList<HashMap<String,String>> c_tmp= new ArrayList<HashMap<String,String>>();
public HashMap<String,String>mapa=new HashMap<String, String>();
String[] name_Val = null;
Can anyone help me how to store in a String[] the following line name_Val
name_Val = (String[]) c_tmp.toArray(new String[c_tmp.size()]);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,name_Val);
I get this exception
java.lang.ArrayStoreException: source[0] of type Ljava/util/HashMap; cannot be stored in destination array of type [Ljava/lang/String;
You are trying to flatten a map, which is a set of key/value pairs into a flat list of values. What’s supposed to happen to the keys here? Your
c_tmpvariable is a list ofHashMaps, which is probably not what you want.If you only want the values from the map and you want to discard the keys, do this:
You can then convert the
Listinto an array should you so desire.