在 Android Studio 中出现以下错误:
获取:
java.lang.ArrayStoreException: source[0] of type com.example.glide.ImageList cannot be stored in destination array of type java.lang.String[] in this line
代码:
ArrayList<ImageList> list = new ArrayList<>();
Object[] objNames = list.toArray();
String[] strNames = Arrays.copyOf(objNames, objNames.length, String[].class);
for(int j=0; j < strNames.length; j++){
strNames[j] = String.valueOf(list.get(j));
Log.d("String : {} ", strNames[i]);
}
最佳答案
你的程序有很多逻辑错误。
但试试这个
public static void main(String[] args) {
ArrayList<ImageList> list = new ArrayList<>();
list.add(new ImageList()); //adding some dummy objects, you add yours
list.add(new ImageList());
String[] strNames = new String[list.size()];
for(int j=0; j < strNames.length; j++){
strNames[j] = String.valueOf(list.get(j));
Log.d("String : {} ", strNames[i]);
}
}
关于java - 如何解决 java.lang.ArrayStoreException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56197631/