Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type A is already defined error

Tags:

java

eclipse

I tried to search for the solution, but what I found I don't know how to apply in this situation. Please help me correct my code.

package Exercise;

public class Ex11_11 {
public static void main(String[] args) {
    A a = new A(3);
    }
}

class A extends B { // type A is already defined, A has a red underline
    public A (int t) {
    System.out.println("A's constructor is invoked");
    }
}

class B { // type B is already defined, B has a red underline
    public B () {
        System.out.println("B's constructor is invoked");
    }  
}
like image 388
Susu Avatar asked Oct 26 '13 19:10

Susu


4 Answers

Eclipse sometimes gets confused. If you choose Clean from the Project menu, it might fix these errors.

like image 51
Robin Green Avatar answered Oct 05 '22 21:10

Robin Green


Well, the first thing to check is obviously whether or not you have another class called A in your file or in the same package.

like image 38
skynet Avatar answered Oct 05 '22 20:10

skynet


I had the same problem. My computer was restarted remotely by I.T, and Eclipse did not shut down gracefully. I noticed there was an extra java file in my project that I didn't add. Deleted it, and now the error is gone.

like image 20
ironarm Avatar answered Oct 05 '22 19:10

ironarm


Check if all your class files are saved. I've had this problem a few times: i define a class in a class file then move it in it's own one. Java gets confised, because it reads from the old version of the original file. Once you save it with the missing class definition in it and define the class in the new file all should be ok.

like image 36
Валентин Стайков Avatar answered Oct 05 '22 21:10

Валентин Стайков