Home  >  Forum  >  Core Java
Post New Query

"main" java.lang.Error: Unresolved compilation problems

joined on
September 16,2014
Asked on March 21,2015
While learning the polymorphism in java I have created a list MyAnimalList and I want to add Animals in the list like Dog and Cat. The size of list is 5 but when I compile it, it throw some exception.

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
Cat cannot be resolved to a type
Cat cannot be resolved to a type
The method add(Animal) in the type MyAnimalList is not applicable for the arguments (Dog)


class MyAnimalList {
private Animal [] animals = new Animal[5];
private int nextIndex = 0;
public void add(Animal a) {
if(nextIndex < animals.length){
animals[nextIndex] = a;
System.out.println("Animal added at " + nextIndex);

public class AnimalTestDrive {
public static void main(String[] args) {
MyAnimalList list = new MyAnimalList();
Dog a = new Dog();
Cat c = new Cat();


Can any one short out the problem? 

joined on
October 10,2013
Replied on March 22,2015

Error says that, there is compilation error in your code. According to the error message

Cat cannot be resolved to a type
Cat cannot be resolved to a type

Cat class is not accessible, it may be because

1. You have not imported the class Cat or
2. You don't have any such class.

Write Answer

Copyright ©2017 concretepage.com, all rights reserved |Privacy Policy | Contact Us