circled.java:14: unreported exception java.lang.CloneNotSupportedException; mustbe caught or declared to be thrown
mypoint p2=(mypoint)p1 .clone();
请问这是什么地方错了,
求高手帮忙了,
你说得很对,我加了try catch后,没再出现这个错误,但又出现了另一个错误提示, mycircle.java:23: missing return statement } 我的源代码如下: circled.java import javax.swing.JOptionPane; import java.lang.CloneNotSupportedException; public class circled { private static String heads ="this is a cirle"; public static void main(String argv[]) { try { System.out.println(heads); String inp; int r; inp=JOptionPane.showInputDialog("input radius:"); r=Integer.parseInt(inp); mypoint p1=new mypoint(10,10); mypoint p2=(mypoint)p1.clone(); System.out.println("center at :"+p1); System.out.println("center at :"+p2); mycircle c1=new mycircle(p1,r); mycircle c2=(mycircle)c1.clone();
c1.printarea(); c1.centerat(); c2.printarea(); c2.centerat(); } catch(Exception e) { System.out.println(e); } }
} mycircle.java public class mycircle implements Cloneable { private static int cc=1; private mypoint p=new mypoint(); private int r; private int index; public mycircle(mypoint p,int r) { this.p=p; this.r=r; index=cc++; } public mycircle(mypoint p) { this(p,10); } public Object clone() throws CloneNotSupportedException { mycircle cir1=(mycircle)super.clone(); cir1.p=(mypoint)p.clone(); } public void centerat() { System.out.println("center at :"+p); } public void printarea() { System.out.println("circle "+index+"with area " +Math.PI * r * r); } } mypoint.java public class mypoint implements Cloneable { private int x,y; public mypoint(int x,int y) { this.x=x; this.y=y; }
public mypoint() { this(0,0); } public Object clone() throws CloneNotSupportedException { return super.clone(); } public int getx() { return x; } public int gety() { return y; } public void setx(int x) { this.x=x; } public void sety(int y) { this.y=y; } public String toString() { return "("+x+","+y+")"; } }
高手请帮忙了!!!
[此贴子已经被作者于2005-9-8 17:07:27编辑过]