,所以我玩弄一些代碼,當我運行它,我得到這個錯誤,空指針異常與ArrayList的
Exception in thread "main" java.lang.NullPointerException
at VRSolution.findSavings(VRSolution.java:35)
at VRTests.main(VRTests.java:22)
這是我的代碼
public void testAlgo() {
this.soln = new ArrayList<List<Customer>>();
int max = this.prob.depot.c;
int current = 0;
ArrayList<Customer> route = null;
for(Customer c:prob.customers){
if(current <= max){
route.add(c);
current += c.c;
}
else {
route = new ArrayList<Customer>();
soln.add(route);
}
}
}
如果有人可以幫助我明白爲什麼我得到這將是非常感謝謝謝
什麼'prob'?你能粘貼相關的代碼嗎? – asgs 2014-10-30 19:27:29
您正在對初始化爲null的'route'變量調用'add'方法。 – 2014-10-30 19:27:47