Javac error: class names are only accepted if annotation processing is explicitly requested

I get this error when compiling my java program:

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

Here is the java code (I am running this on Ubuntu).

 import jcuda.CUDA; import jcuda.driver.CUdevprop; import jcuda.driver.types.CUdevice; public class EnumDevices { public static void main(String args[]) { CUDA cuda = new CUDA(true); int count = cuda.getDeviceCount(); System.out.println("Total number of devices: " + count); for (int i = 0; i < count; i++) { CUdevice dev = cuda.getDevice(i); String name = cuda.getDeviceName(dev); System.out.println("Name: " + name); int version[] = cuda.getDeviceComputeCapability(dev); System.out.println("Version: " + String.format("%d.%d", version[0], version[1])); CUdevprop prop = cuda.getDeviceProperties(dev); System.out.println("Clock rate: " + prop.clockRate + " MHz"); System.out.println("Threads per block: " + prop.maxThreadsPerBlock); } } } 

Here is the javac command:

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

How to compile this program?

+88
java javac
Feb 21 '11 at 7:15
source share
13 answers

At least you need to add the .java to the file name on 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 when explicitly requesting annotation processing

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

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

+97
Feb 21 '11 at 7:23
source share

I was shocked by this because I turned on the .Java extension ... then I noticed the capital J.

This will also throw an “annotation processing” error:

 javac myclass.Java 

Instead, it should be:

 javac myclass.Java 
+13
Aug 30 '13 at 21:00
source share

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

+4
Jun 6 '16 at 20:17
source share

I found out that you can also get this error by saving the source file in a folder named Java

+3
Sep 01 '17 at 21:50
source share
 chandan@cmaster:~/More$ javac New.java chandan@cmaster:~/More$ javac New error: Class names, 'New', are only accepted if annotation processing is explicitly requested 1 error 

So, if you mistakenly use javac again after compilation to run the program.

+1
Nov 09 '15 at 13:42 on
source share

How can you reproduce this cryptic error on an Ubuntu terminal:

Put this in the Main.java file:

 public Main{ public static void main(String[] args){ System.out.println("ok"); } } 

Then compile it as follows:

 user@defiant /home/user $ javac Main error: Class names, 'Main', are only accepted if annotation processing is explicitly requested 1 error 

This is because you did not specify .java at the end of Main .

Do it like this and it works:

 user@defiant /home/user $ javac Main.java user@defiant /home/user $ 

Now break your forehead and grumble that the error message is so cryptic.

0
Sep 18 '14 at 18:57
source share

The error "Class names are accepted only when the annotation is explicitly processed" can be caused by one or more of the following elements:

  • Do not use the .java extension for your java file when compiling.
  • Incorrect capitalization of the .java extension (i.e. Java) during compilation.
  • Any other typo in the .java extension during compilation.
  • When compiling and starting at the same time, forgetting to use '& &' to combine the two commands (i.e. javac Hangman.java java Hangman). It took me 30 minutes to figure this out, which I noticed running the compilation and running the program separately, which, of course, worked great.

This may not be a complete list of the causes of this error, but these are the reasons that I still know about.

0
Mar 16 '15 at 6:14
source share

Perhaps you are compiling the file name instead of the method name .... Check as soon as I made the same mistake too, but I fixed it quickly ..... # happy Coding

0
Apr 23 '18 at 10:53
source share

first download jdk from https://www.oracle.com/technetwork/java/javase/downloads/index.html . Then in the search write Edit system environment variables. In the window that opens, I click on the bottom called Environment Variables. Then in the system variables, enter a description of the image here. Click the bottom. In the new variables field, write "Path". The field is the new value. C: \ Program Files \ Java \ jdk1.8.0_191 \ bin ", but only" C: \ Program Files \ Java \ jdk1.8.0_191 \ bin \ javac.exe "works on my OS; enter a description of the image here click ok 3 times

Launch Cmd. I click the bottom windows + R. Then type cmd. In cmd write "cd (your directory with code)", it looks like C: \ Users \ user \ IdeaProjects \ app \ src. Then write “javac (the name of your main class for your program) .java” looks like blabla.java, and javac creates a bytecode similar to (the name of your main class) .class in your directory. write "java (the name of your main class)" in cmd for the last time and my program will start working

0
Apr 02 '19 at 16:58
source share

Error: class name only accepted if annotation processing is explicitly request

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

Javac DescendingOrder.java <- this works great.

0
Jun 15 '19 at 6:21
source share

I think this is also due to improper compilation ..

so for Linux (ubuntu) .....

javac file.java

Java file

0
Jul 6 '19 at 13:24
source share

If the ur file is saved as an example: hello.java and

class Example. This is in cmd

javac hello.java

java example

It works.

-2
Jul 30 '17 at 18:16
source share

you are viewing javac.exe and java.exe path

D: \ Test> "C: \ jdk1.7.0_80 \ bin \ javac.exe" TestMain.java D: \ Test> "C: \ jdk1.7.0_80 \ bin \ java.exe" TestMain.java

-2
Jul 13 '18 at 8:14
source share



All Articles