我正在爲我的大學的一個項目,我在 Assignment2.ColumnGen $ SubProblem.createModel(ColumnGen總是得到相同的錯誤消息數值誤差圖implementantion
顯示java.lang.NullPointerException。 Java的:283)
的問題是在這些線路
double M = 0;
for (int i=0; i<all_customers.size(); i++) {
for (int j=0; j<all_customers.size(); j++) {
double val = all_customers.get(i).time_to_node(all_customers.get(j)) + all_customers.get(i).time_at_node();
if (M<val) M=val;
}
}
當我刪除這些行的一切禾rks完美,但顯然我沒有得到最好的結果,只要我的算法,因爲我想念這個參數。
我知道什麼是空指針異常,但我嘗試了一切,但仍然想念一些東西。
我的所有其他聲明爲您在代碼中看到的東西都是
public Map<Integer, Customer> all_customers = new HashMap<Integer, Customer>();
public double a() {
return ready_time;
}
public double b() {
return due_date;
}
public Node(int external_id, double x, double y, double t) {
this.id = all_nodes.size();
this.id_external = external_id;
this.xcoord = x;
this.ycoord = y;
this.t_at_node = t;
all_nodes.put(this.id, this);
}
public double time_to_node(Node node_to) {
return Math.round(Math.sqrt(Math.pow(this.xcoord - node_to.xcoord, 2) + Math.pow(this.ycoord - node_to.ycoord, 2)));
}
public double time_at_node() {
return t_at_node;
}
我該怎麼辦了?
你在哪裏添加數據到變量all_customers?你只是實例化一個HashMap並分配給變量,但沒有數據。所以當你嘗試在循環中運行它時會產生異常。 – Dez