javac error: Class names are only accepted if annotation processing is explicitly requested

后端 未结 12 718
余生分开走
余生分开走 2020-11-27 04:37

I get this error when I compile my java program:

error: Class names, \'EnumDevices\', are only accepted if annotation 
processing is explicitly requested
1          


        
相关标签:
12条回答
  • 2020-11-27 04:58

    The error "Class names are only accepted if annotation processing is explicitly requested" can be caused by one or more of the following:

    1. Not using the .java extension for your java file when compiling.
    2. Improper capitalization of the .java extension (i.e. .Java) when compiling.
    3. Any other typo in the .java extension when compiling.
    4. When compiling and running at the same time, forgetting to use '&&' to concatenate the two commands (i.e. javac Hangman.java java Hangman). It took me like 30 minutes to figure this out, which I noticed by running the compilation and the running the program separately, which of course worked perfectly fine.

    This may not be the complete list of causes to this error, but these are the causes that I am aware of so far.

    0 讨论(0)
  • 2020-11-27 05:01

    Using javac ClassName.java to compile the program, then use java ClassName to execute the compiled code. You can't mix javac with the ClassName only (without the java extension).

    0 讨论(0)
  • 2020-11-27 05:02

    I learned that you also can get this error by storing the source file in a folder named Java

    0 讨论(0)
  • 2020-11-27 05:03

    You at least need to add the .java extension to the file name in this line:

    javac -cp /home/manish.yadav/Desktop/JCuda-All-0.3.2-bin-linux-x86_64 EnumDevices
    

    From the official faq:

    Class names, 'HelloWorldApp', are only accepted if annotation processing is explicitly requested

    If you receive this error, you forgot to include the .java suffix when compiling the program. Remember, the command is javac HelloWorldApp.java not javac HelloWorldApp.

    Also, in your second javac-example, (in which you actually included .java) you need to include the all required .jar-files needed for compilation.

    0 讨论(0)
  • 2020-11-27 05:03

    To avoid this error, you should use javac command with .java extension.

    Javac DescendingOrder.java <- this work perfectly.

    0 讨论(0)
  • 2020-11-27 05:06

    If you compile multiple files in the same line, ensure that you use javac only once and not for every class file.

    Incorrect:

    Correct:

    0 讨论(0)
提交回复
热议问题