【发布时间】:2012-05-20 18:49:40
【问题描述】:
这是我第一次真正使用列表和队列,所以这可能是一个非常简单的错误。是因为我的队列中充满了无法转换为整数的对象吗?
//populate array
for(int i=0; i<11; i++){
numberarray[i] = i;
}
// populate list with numbers from array
List numList = Arrays.asList(numberarray);
Collections.shuffle(numList);
Queue queue = new LinkedList();
queue.addAll(numList);
int num1 = (Integer) queue.poll();
assignPictures(button01, num1);
【问题讨论】:
-
您得到的
ClassCastException是什么?为什么不使用泛型来确保类型安全? -
java.util.Arrays$ArrayList 不能转换为 java.lang.Integer...泛型是指 List
? -
我的意思是
List<Integer>。基元不能用作类型参数 -
谢谢.. 我尝试使用 List
而不是 List 。
标签: java arraylist queue classcastexception