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());
}
}
}
Error: I am getting a null pointer exception in the second code. However when I try to just assign the passed object in constructor, it works fine.