There is an interface
public interface Rtriangle {
int getApexX1();
int getApexY1();
int getApexX2();
int getApexY2();
int getApexX3();
int getApexY3();
}
And a class that implement this interface
public class RightTriangle implements Rtriangle{
private Point a;
private Point b;
private Point c;
public RightTriangle (int x1, int y1, int x2, int y2, int x3, int y3){
this.a.x=x1;
this.a.y=y1;
this.b.x=x1;
this.b.y=y1;
this.c.x=x1;
this.c.y=y1;
}
public int getApexX1(){
return a.x;
}
public int getApexY1(){
return a.y;
}
public int getApexX2() {
return b.x;
}
public int getApexY2(){
return b.y;
}
public int getApexX3(){
return c.x;
}
public int getApexY3(){
return c.y;
}
}
Also there is a class that uses this class:
public class RtriangleProvider {
public static Rtriangle getRtriangle(){
try{
Rtriangle tr = new RightTriangle(0, 0, 0, 2, 2, 0);
return tr;
}
catch(Exception e){
System.out.print(e.toString());
return null;
}
}
}
And when I try to use getRtriangle() method I'm getting NullPointerException exception on this line:
Rtriangle tr = new RightTriangle(0, 0, 0, 2, 2, 0);
on RightTriangle creation.
public class TestTriangle {
@Test
public void testRight(){
Rtriangle tr =RtriangleProvider.getRtriangle();
}
}
I can't understand what is the problem with constructor.I will appreciate any advice.