,所以我玩弄一些代码,当我运行它,我得到这个错误,空指针异常与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