java制造null异常_null异常java

我收到一个错误,说java.lang.NullPointerException:null

从代码每当我运行它。

代码如下:

public class APRectangle

{

private APPoint myTopLeft;

private APPoint myTopRight;

private APPoint myBottomLeft;

private APPoint myBottomRight;

private double myWidth;

private double myHeight;

public APRectangle( APPoint topLeft, double width, double height )

{

myTopLeft = topLeft;

myWidth = width;

myHeight = height;

}

public APPoint getTopLeft()

{

return myTopLeft;

}

public void setTopLeft( APPoint TL )

{

myTopLeft = TL;

}

public double getWidth()

{

return myWidth;

}

public void setWidth( double W )

{

myWidth = W;

}

public double getHeight()

{

return myHeight;

}

public void setHeight( double H )

{

myHeight = H;

}

public APPoint getTopRight()

{

return new APPoint( myTopLeft.getX() + myWidth, myTopLeft.getY() );

}

public APPoint getBottomLeft()

{

return new APPoint( myTopLeft.getX(), myTopLeft.getY() - myHeight );

}

public APPoint getBottomRight()

{

return new APPoint( myTopRight.getX(), myTopRight.getY() - myHeight );

}

}最后一种方法是给我错误的方法。

这是我的主要课程:

public class MainClass

{

public MainClass()

{

}

public static String printAPPoint( APPoint p )

{

return "(" + p.getX() + "," + p.getY() + ")";

}

public static String printAPRectangle( APRectangle R)

{

return "[APRectangle " + printAPPoint(R.getTopLeft()) +

" " + R.getWidth() + "," + R.getHeight() + "]" ;

}

public static String printTopLeft( APRectangle R )

{

return "(Top Left is " + printAPPoint(R.getTopLeft()) + ")" ;

}

public static String printTopRight( APRectangle R )

{

return "(Top Right is " + printAPPoint(R.getTopRight()) + ")" ;

}

public static String printBottomLeft( APRectangle R )

{

return "(Bottom Left is " + printAPPoint(R.getBottomLeft()) + ")";

}

public static String printBottomRight( APRectangle R )

{

return "(Bottom Right is " + printAPPoint(R.getBottomRight()) + ")";

}

public static void main(String[] args)

{

APPoint p = new APPoint(1.0, 5.0 );

APRectangle R = new APRectangle( p, 5.0, 3.0);

System.out.println(printAPRectangle(R));

System.out.println(printTopLeft(R));

System.out.println(printTopRight(R));

System.out.println(printBottomLeft(R));

System.out.println(printBottomRight(R));

System.out.println( "Done!" );

}

}最后一种方法的三种方法工作得很好,但我不知道最后一种方法不起作用的原因。有人能帮助我吗?

谢谢,罗汉

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值