问题描述
- IDE运行时,报错的问题
-
class Point{
private double x;
private double y;Point(double _x,double _y){ x = _x; y = _y; } void setX(double _x){ x = _x; } void setY(double _y){ y = _y; } double getX(){ return x; } double getY(){ return y; }
}
class Circle{
Point o;
double radius;Circle(Point p, double r){ o = p; radius = r; } Circle(double r){ o = new Point(0.0,0.0); radius = r; } void setO(Point p){ o = p; } void setRadius(double r){ radius = r; } Point getO(){ return o; } double getRadius(){ return radius; } boolean contaons(Point p){ double x = o.getX() - p.getX(); double y = o.getY() - p.getY(); if (x*x + y*y > radius*radius) return false; else return true; } double area(){ return 3.14*radius*radius; }
}
public class TestCircle {public static void main(String[] args) { Circle c1 = new Circle(new Point(3.0,4.0),2.0); Circle c2 = new Circle(4.0); System.out.println("c1的圆心坐标,半径分别是:"+"("+c1.getO().getX()+","+c1.getO().getY()+")"+";"+c1.getRadius()); System.out.println("c2的圆心坐标,半径分别是:"+"("+c2.getO().getX()+","+c2.getO().getY()+")"+";"+c2.getRadius()); System.out.println("c1's area is "+c1.area()); System.out.println("c2 's area is "+c2.area()); c1.getO().setX(6.0); System.out.println("修改后c1的坐标为:"+"("+c1.getO().getX()+","+c1.getO().getY()+")"); System.out.println("修改后c1的面积:"+c1.area()); Point p = new Point(1.0,3.0); System.out.println("点()是否在圆c1中"+c1.contaons(p)); }
}
```这一段代码,在控制台编译没有报错,正确输出,但是在eclipse中运行时报错,说Exception in thread "main" java.lang.NoSuchMethodError: Point.<init>(DD)V at TestCircle.main(TestCircle.java:66) 这个错误,怎么回事呢? ![图片说明](http://img.ask.csdn.net/upload/201601/17/1453016970_183892.png)
解决方案
66行,是那一行呢?出错信息已经说明是66行的问题,你能标明这一行不
解决方案二:
不是吧,我测试了你的代码了,如果写在Eclipse环境中,新建三个类Circle,Point ,TestCircle,拷贝了你的代码后能够正常运行的结果为:
c1的圆心坐标,半径分别是:(3.0,4.0);2.0
c2的圆心坐标,半径分别是:(0.0,0.0);4.0
c1's area is 12.56
c2 's area is 50.24
修改后c1的坐标为:(6.0,4.0)
修改后c1的面积:12.56
点()是否在圆c1中false
我的环境是jdk1.8 Eclipse Mars Release (4.5.0),代码没有问题的。
时间: 2024-10-21 09:26:57