for (final ArrayList<SmartPhone> smartPhones : smartPhonesCluster) {
new Thread(new Runnable() {
@Override
public void run() {
for (SmartPhone smartPhone : smartPhones) {
Queue<SmartPhoneTask> tasks = smartPhone.getSystem()
.getTaskQue();
SmartPhoneTask task = null;
assert tasks != null;
try {
while (!tasks.isEmpty()) {
task = tasks.poll(); // This is the line throwing the exception (GlobalNetwork.java:118)
assert task != null;
task.execute();
task.onTaskComplete();
}
} catch (RuntimeException e) {
e.printStackTrace();
}
}
}
}).start();
}
并记录:
java.util.NoSuchElementException
at java.util.LinkedList.remove(LinkedList.java:788)
at java.util.LinkedList.removeFirst(LinkedList.java:134)
at java.util.LinkedList.poll(LinkedList.java:470)
at com.wtsang02.reu.botnet.network.GlobalNetwork$1.run(GlobalNetwork.java:118)
at java.lang.Thread.run(Thread.java:662)
java.lang.NullPointerException
Exception in thread "Thread-299" java.lang.AssertionError
at com.wtsang02.reu.botnet.network.GlobalNetwork$1.run(GlobalNetwork.java:119)
at java.lang.Thread.run(Thread.java:662)
第 118 行指向:
task=tasks.poll();
如何解决这个问题?队列是 LinkedList 实现,如果这有所作为。