Hi I have written such this code but it will return this exception .and I do not know why please help me thanks.
private void Scan(DoublyLinkedList dList) { // T(n) = O(n)
DNode p1 = dList.getFirst();
while (p1!=null) {
DNode p2 = p1.next;
System.out.println(p1.getElement().toString()+"lol");
if (p2.next!=null) {
DNode p3 = p2.next;
if(p3.getElement()!=null){
boolean b = Determinate.isPointRightSide(p1.getElement(), p2.getElement(),p3.getElement());
if (b == true) {
p1 = p1.next;
} else {
p1.next = p3;
p3.prev = p1;
dList.remove(p2);
p1 = p1.prev;
}
}
else break;
}else break;}
}
public static double determinate(Object get, Object get0, Object get1) {
double data[][] = new double[3][2];
data[0][0] = ((Point) get).getX();
data[0][1] = ((Point) get).getY();
data[1][0] = ((Point) get0).getX();
data[1][1] = ((Point) get0).getY();
**data[2][0] = ((Point) get1).getX();**
data[2][1] = ((Point) get1).getY();
return ((data[0][0] * (data[1][1] - data[2][1])) - (data[1][0] * (data[0][1] - data[2][1])) + (data[2][0] * (data[0][1] - data[1][1])));
}
exception:
run:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at ConvexHull.Determinate.determinate(Determinate.java:55)
at ConvexHull.Determinate.isPointRightSide(Determinate.java:15)
at ConvexHull.GrahamVersion.Scan(GrahamVersion.java:104)
at ConvexHull.GrahamVersion.grahamScan(GrahamVersion.java:83)
at ConvexHull.GrahamVersion.<init>(GrahamVersion.java:25)
at UI.MainFrame.grahamButtonActionPerformed(MainFrame.java:221)
this will show that "p3" is null! but I have check "p3" why it returns "null" again? I use strong for showing those lines that throws exception.
EDIT: Ihave edited my post but it will throw this exception for "p1"
getobjects are notnull?p3.getElement()(not p3) is null since that's what is initializingget1.