什么是错在这里?我得到一个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错误,但我看不到的地方我已经错了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我第一次真正使用链表和队列所以这可能是一个非常简单的错误。难道是因为我的队列已满,不能转换为整数的对象?
//填充阵列
的for(int i = 0; I< 11;我++){
numberarray [我] =我;
}
//填充与数组号码列表
清单numList = Arrays.asList(numberarray);
Collections.shuffle(numList); 排队长龙=新的LinkedList();
queue.addAll(numList); INT NUM1 =(整数)queue.poll();
assignPictures(button01,NUM1);
解决方案
您真的应该,除非它是真正的性能至关重要,并且您使用了大量的原子类型如int的使用泛型和ArrayList / ArrayDeque。那么你应该看一看
http://labs.carrotsearch.com/hppc.html
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);
解决方案
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屋!
查看全文