Java error - bad source file: file does not contain class x . Please remove or make sure it appears

后端 未结 5 1368
你的背包
你的背包 2020-11-30 12:36

Recently started studying Java for an exam.

While learning packages, tried this and got an error message. What I did was,




        
5条回答
  •  野性不改
    2020-11-30 13:33

    every thing is in right place, java does not ask to put your A.java file, in the helpers folder

    the whole reason why your code ran with the A.java file removed and not otherwise is: when your app.java (or the main java file which is importing other classes in it, -->) is in a default package then while importing the classes it gives priority to the same directory and not to the package directory(if there exist any file that has the same name as the class file -> and thats why it gives error bad source file A.java -> as it wanted A.class)

    And because of that there is a rule in java : That never place a .java file (of the same name)in parallel to the packages

    so to solve this problem you have to either remove the file, A.java or rename it (to any other name that does not present in the package) or you can use fully qualified import statement

提交回复
热议问题