这里有什么问题?我收到一个 java.lang.ClassCastException 错误,但我看不出哪里出错了 [英] What is wrong here? I get a java.lang.ClassCastException error but I can't see where I have gone wrong
本文介绍了这里有什么问题?我收到一个 java.lang.ClassCastException 错误,但我看不出哪里出错了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我第一次真正使用列表和队列,所以这可能是一个非常简单的错误.是不是因为我的队列中充满了无法转换为整数的对象?
This is the first time I have really used Lists and Queues so this might be a very simple mistake. Is it because my queue is full of objects that can't be cast to integers?
//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);
推荐答案
你真的应该使用泛型和 ArrayList/ArrayDeque,除非它真的很关键,而且你使用了很多原子类型,比如 int.那你应该看看http://labs.carrotsearch.com/hppc.html
You really should use Generics and ArrayList/ArrayDeque unless it's really performance critical and you use a lot of atomic types like int. Then you should have a look at http://labs.carrotsearch.com/hppc.html
这篇关于这里有什么问题?我收到一个 java.lang.ClassCastException 错误,但我看不出哪里出错了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文