Klonowanie proszę o pomoc

0

Exception in thread "main" java.lang.CloneNotSupportedException: Punkt
at java.lang.Object.clone(Native Method)
at Punkt.clone(Punkt.java:7)
at Glowny.main(Glowny.java:7)

Witam, mam pewnien problem i nie wim jak go rozwiązać, wyskakuje mi taki błąd podczas klonowania
a oto kod:



public class Glowny {

	public static void main(String[] args) throws CloneNotSupportedException {

		Punkt punkt = new Punkt(10, 10);
		Punkt b = (Punkt) punkt.clone();
		Punkt c = new Punkt(10, 10);
		
		boolean chooseA = punkt == b;
		boolean chooseB = punkt == c;
		System.out.println("Porownanie Punkt 1 i Punkt 2: "+ chooseA);
		System.out.println("Porownanie Punkt 1 i Punkt 3: "+ chooseB);
	}

}


public class Punkt implements Cloneable {
	private int x;
	private int y;
	  public Punkt clone() throws CloneNotSupportedException
	  {
	        return (Punkt)super.clone();
	  }
	public Punkt(int a, int b)
	{
		x = a;
		y= b;
	}
	public int setPunktX()
	{
		return x;
	}
	public int setPunktY()
	{
		return y;
	}
 
}

Proszę o pomoc i z góry dziękuje.

0

Dobra, ale teraz jak ma to rozwiązać, tak żeby mi działał program.

0

A potrafisz czytać?

Thrown to indicate that the clone method in class Object has been called to clone an object, but that the object's class does not implement the Cloneable interface.

Jeszcze jeden link dla ułatwienia http://docs.oracle.com/javase/7/docs/api/java/lang/Cloneable.html

1 użytkowników online, w tym zalogowanych: 0, gości: 1