I don't understand why this is giving me a class cast exception:
List<String> names = new ArrayList<String>();
for (ApplicationInfo app : apps) {
names.add("" + app.loadLabel(packageManager));
}
return (String[]) names.toArray();
the log is:
01-23 16:56:18.746: E/AndroidRuntime(4027): Caused by: java.lang.ClassCastException: java.lang.Object[] cannot be cast to java.lang.String[]
but I clearly defined names
to be a list of String
and not Object
**EDIT:
oh wait, okay i see in the API it returns array of objects. how could i do this without doing:
List<String> names = new ArrayList<String>();
for (ApplicationInfo app : apps) {
names.add("" + app.loadLabel(packageManager));
}
String[] list = new String[names.size()];
return names.toArray(list);
and making a new array each time?