class Cell {
Point ob ;
int distance;
public Cell(Point x, int i) {
try {
ob = x;// works fine
distance = i;
} catch (Exception e) {
System.out.println(e.getStackTrace());
}
}
}
class Cell {
Point ob ;
int distance;
public Cell(Point x, int i) {
try {
ob.x = x.x; // throws null pointer exception
ob.y = x.y;
distance = i;
} catch (Exception e) {
System.out.println(e.getStackTrace());
}
}
}
錯誤:我在第二個代碼中收到空指針異常。但是,當我嘗試只分配在構造函數中傳遞的對象,它工作正常。點類java空指針異常
你可以包含你的代碼實例'Cell'嗎? – Chris