0

I am getting this error message:

Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: Pet.saySomething at PetTest.main(PetTest.java:18) Java Result: 1

Here is what i have: for the Speak class,

public class Speak {
   public void saySomething();
}

Here is what i have in the PetTest class:

 import java.util.ArrayList;

 public class PetTest {

     public static void main(String[] args)
     {
         ArrayList<Pet> myPets = new ArrayList<Pet>();

         myPets.add(new Parrot("Boss"));
         myPets.add(new Cat("Oreo"));
         myPets.add(new Dog("Riley"));

         for (Pet p: myPets)
         {
             p.saySomething();
             System.out.println(p);
         }
     }
 }

I did not post the other 5 classes that go with this program. I know there is something that needs to be fixed in the Speak class, but i am stuck. In the Speak class, on the line that says public void saySomething(); it says Missing Method body, or declare abstract.

EDIT: Here are the other classes:

 public abstract class Pet {

     String name;

     public Pet(String name){
         this.name = name;
     }
 }

 public class Parrot extends Bird {

     public Parrot (String name)
     {
         super(name);
     }

     @Override
     public void saySomething()
     {
         System.out.println("Pauly want a craker?");
     }

     @Override
     public String toString()
     {
         return "Hello, I'm " + name + " the parrot.";
     }

 }


 public class Dog extends Pet {

     public Dog (String name)
     {
         super(name);
     }

     @Override
     public void saySomething()
     {
         System.out.println("Ruff, ruff!");
     }

     @Override
     public String toString()
     {
         return "Hello, I'm " + name + " the dog.";
     }
 }


 public class Cat extends Pet {

     public Cat(String name)
     {
         super(name);
     }

     @Override
     public void saySomething()
     {
    System.out.println("Meow.");
     }

     @Override
     public String toString()
     {
         return "Hello, I'm " + name + " the cat.";
     }
 }

 public class Bird extends Pet {

     public Bird(String name)
     {
         super(name);
     }

     public void saySomething(){}

 }
3

2 Answers 2

1

You have the following options for Speak, take your pick:

1st

public abstract class Speak{

   public abstract void saySomething();

}

2nd

public class Speak{

   public void saySomething(){

   }
}

3rd

public interface Speak{

   public void saySomething();
}

Edit: First of all, you are not using Speak class anywhere. Second, please add the following method in Pet class:

 public abstract void saySomething();
2
  • I tried all 3 of those choice, but i am still receiving Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: Pet.saySomething at PetTest.main(PetTest.java:18) Java Result: 1 Mar 27, 2015 at 5:15
  • That worked perfectly. As you can tell i am no expert in java. Thank you for the help Mar 27, 2015 at 5:48
1

If Speak is a concrete class, it must implement all of its methods, so saySomething must have a body.

However, it looks like Speak is more suitable to be an interface. Your Pet class can implement that interface.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.