Java class “cannot be resolved to a type”

前端 未结 4 1510
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-10 18:50

This is the error I\'m getting:

Exception in thread \"main\" java.lang.Error: Unresolved compilation problem:  
             


        
4条回答
  •  抹茶落季
    2020-12-10 19:55

    Your exception message says this

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

    This means that you have tried to run a program that used some class that has not compiled correctly.

    Go back and fix the compilation error(s).

    It is not clear what the fix for the compilation error should be, but the error is saying that it cannot find a class called TeamLeader. Perhaps it doesn't exist. Perhaps it is in a different package. Perhaps you haven't compiled it. Perhaps something else.


    Looking at the code, I think the problem is that you have defined two distinct classes called TeamLeadDemo, one as a nested class of Employee and the second as a top-level class. Furthermore the second of these is attempting to use TeamLeader ... but the TeamLeader class that you have actually declared is nested 2 levels down in Employee; i.e. its real name is Employee.ShiftSupervisor.TeamLeader.

    This is all a bit nonsensical.

    By the look of it, you defined a whole bunch of classes in the same file ("Employee.java") without much understanding of what it means to put one class inside another. Most likely, each of those classes should be declared in its own file. And most likely you should just delete the nested TeamLeadDemo class.

提交回复
热议问题