Java :erreur de compilation

domxaline -  
KX Messages postés 19031 Statut Modérateur -
Bonjour,
j'ai une erreur lors de compilation,veuillez aidez moi svp
abstract public class Figure 
{
 int x,y;
 void changePosition (int newX,int newY)
 { }
 abstract void draw();
 {}
}

public class CirculeObject extends Figure
{
  void draw()
  {
	  System.out.println("Draw method called");
  }
}

public class RectangleObject extends Figure 
{
 void changePosition(int newX,int newY)
 {
	 System.out.println("change position method called");
 }
 public static void main(String[]args)
 {
	FigureObject f0=new FigureObject(20,15);
	f0.draw();
	CirculeObject f1=new CirculeObject();
	f1.draw();
    RectangleObject f2=new RectangleObject() ;
	f2.changePosition(10,20);
 }
}


Exception in thread "main" java.lang.Error: Unresolved compilation problems:
FigureObject cannot be resolved to a type
FigureObject cannot be resolved to a type

at RectangleObject.main(RectangleObject.java:10)

8 réponses

  1. KX Messages postés 19031 Statut Modérateur 3 020
     
    Si draw est abstraite dans Figure alors :
    1) Tu ne dois pas mettre d'accolades derrière.
    2) Tu dois définir la méthode draw dans RectangleObject sinon elle sera également abstraite et tu ne pourra pas faire d'instanciation (new RectangleObject)
    0
  2. domxaline
     
    vous voulez que je fasse comme ça
    abstract public class Figure 
    {
     int x,y;
     void changePosition (int new x,int new y)
     {
    	 
     }
     abstract void draw();
    }
    
    public class RectangleObject extends Figure 
    {
        //void changePosition(int newX,int newY)
    	void draw(int newX,int newY)
     {
    	 System.out.println("change position method called");
     }
     public static void main(String[]args)
     {
    	FigureObject f0=new FigureObject(20,15);
    	f0.draw();
    	CirculeObject f1=new CirculeObject();
    	f1.draw();
        RectangleObject f2=new RectangleObject() ;
    	f2.changePosition(10,20);
     }
    }
    

    j'ai toujours la même erreur
    Exception in thread "main" java.lang.Error: Unresolved compilation problems:
    FigureObject cannot be resolved to a type
    FigureObject cannot be resolved to a type
    The method changePosition() in the type Figure is not applicable for the arguments (int, int)

    at RectangleObject.main(RectangleObject.java:11)
    0
    1. KX Messages postés 19031 Statut Modérateur 3 020
       
      On ne sais pas ce que c'est FigureObject !
      Tu as Figure, CirculeObject et RectangleObject, mais pas de classe FigureObject...
      0
  3. domxaline
     
    abstract public class Figure
    {
    int x,y;
    void changePosition (int new x,int new y)
    {

    }
    abstract void draw();

    }
    0
  4. domxaline
     
    le correction
    public class RectangleObject extends Figure
    {
    void changePosition(int newX,int newY)
    void draw(int newX,int newY)
    {
    System.out.println("change position method called");
    }
    public static void main(String[]args)
    {
    Figure f0=new Figure(20,15);
    f0.draw();
    CirculeObject f1=new CirculeObject();
    f1.draw();
    RectangleObject f2=new RectangleObject() ;
    f2.changePosition(10,20);
    }
    }
    0
    1. KX Messages postés 19031 Statut Modérateur 3 020
       
      Tu ne peux pas faire de "new Figure" car Figure est abstraite. De même pour RectangleObject qui se retrouve également abstraite puisque tu n'as pas définis la méthode abstraite draw()
      0
  5. Vous n’avez pas trouvé la réponse que vous recherchez ?

    Posez votre question
  6. nini
     
    en générale la sous classe devient abstraite l'orque elle contient une méthode abstraite au fait je vous demande est ce qu'il y a d'autre cas dans le qu'elle la sous classe sois abstraite
    0
    1. KX Messages postés 19031 Statut Modérateur 3 020
       
      Tu peux explicitement mettre le mot clé abstract sur une classe, même si elle n'a pas de méthode abstraite, et elle sera abstraite quand même.

      Par exemple, cette classe n'a aucune méthode abstraite, mais elle est abstraite quand même...

      public abstract class Test
      {
      }
      0
  7. domxaline
     
    abstract public class Figure 
    {
     int x,y;
     
     void changePosition (int x,int y)
     {
    	 
     }
      abstract void draw()
    }
    

    public abstract class CirculeObject extends Figure
    {
      void draw()
      {
    	  System.out.println("Draw method called");
      }
    }
    

    public abstract class RectangleObject extends Figure 
    {
        void changePosition(int newX,int newY)
    	void draw(int newX,int newY)
     {
    	 System.out.println("change position method called");
     }
     public static void main(String[]args)
     {
    	Figure f0=new Figure(20,15);
    	f0.changePosition();
    	CirculeObject f1=new CirculeObject();
    	f1.draw();
        RectangleObject f2=new RectangleObject() ;
    	f2.changePosition(10,20);
     }
    }
    

    Exception in thread "main" java.lang.Error: Unresolved compilation problems:
    Cannot instantiate the type Figure
    The method changePosition(int, int) in the type Figure is not applicable for the arguments ()
    Cannot instantiate the type CirculeObject
    Cannot instantiate the type RectangleObject

    at RectangleObject.main(RectangleObject.java:11)
    0
    1. KX Messages postés 19031 Statut Modérateur 3 020
       
      Tout est dit dans le message !
      Tu fais f0.changePosition(); alors que changePosition attends deux arguments (int, int)
      Apprends à lire les messages d'erreurs !!!
      0
  8. domxaline
     
    public abstract class RectangleObject extends Figure 
    {
        void changePosition(int newX,int newY)
    	void draw(int newX,int newY)
     {
    	 System.out.println("change position method called");
     }
     public static void main(String[]args)
     {
    	Figure f0=new Figure();
    	f0.changePosition(20,15);
    	CirculeObject f1=new CirculeObject();
    	f1.draw();
        RectangleObject f2=new RectangleObject() ;
    	f2.changePosition(10,20);
     }
    }
    

    Exception in thread "main" java.lang.Error: Unresolved compilation problems:
    Cannot instantiate the type Figure
    Cannot instantiate the type CirculeObject
    Cannot instantiate the type RectangleObject

    at RectangleObject.main(RectangleObject.java:11)
    0
  9. domxaline
     
    bonjour j'ai corrigé mon prg ainsi mais toujous j'ai une erreur
    abstract public class Figure 
    {
     int x,y;
     
     void changePosition (int newX,int newY)
     {
    	 
     }
     abstract void draw();
    }
    


    public abstract class CirculeObject extends Figure
     {
      void draw()
      {
    	  System.out.println("Draw method called");
      }
     }
    


    public abstract class RectangleObject extends Figure 
    {
        void changePosition(int newX,int newY)
    	
         {
    	    System.out.println("change position method called");
         }	
     }
    


    public class AbstractEssaie 
    {
    	public static void main(String[]args)
    	 {
    		CirculeObject c=new CirculeObject();
    		Figure figuref;
    		figuref=c;
    		System.out.println("CirculeObject is"+figuref.changePosition(newX,newY));
    		
    		RectangleObject r =new RectangleObject();
    		figuref=r;
    		System.out.println("RectangleObject is"+figuref.draw(x,y));
    		
         }
    }
    

    Exception in thread "main" java.lang.Error: Unresolved compilation problems:
    Cannot instantiate the type CirculeObject
    newX cannot be resolved to a variable
    newY cannot be resolved to a variable
    Cannot instantiate the type RectangleObject
    x cannot be resolved to a variable
    y cannot be resolved to a variable

    at AbstractEssaie.main(AbstractEssaie.java:6)
    0
    1. KX Messages postés 19031 Statut Modérateur 3 020
       
      Il faut lire le message d'erreur qui est pourtant clair, tu utilises dans ton main des variables newX, newY, x et y, qui ne sont pas déclarés et qui n'ont donc aucune valeur !
      0