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(){}

 }
Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332

2 Answers2

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.

Eran
  • 387,369
  • 54
  • 702
  • 768
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();
Touchstone
  • 5,575
  • 7
  • 41
  • 48
  • 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 – Kevin Borkowski Mar 27 '15 at 05:15
  • That worked perfectly. As you can tell i am no expert in java. Thank you for the help – Kevin Borkowski Mar 27 '15 at 05:48