Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

javac

I get this error when I compile my java program:

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

Here is the java code (I'm 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 do I compile this program?

like image 212
user513164 Avatar asked Feb 21 '11 07:02

user513164


People also ask

How do you fix class names are only accepted if annotation processing is explicitly requested?

Solution: class names are only accepted if annotation processing is explicitly requested. We can simply resolve this issue by appending . java at the end of file name and it should resolve the issue.

Are only accepted if annotation processing is explicitly requested are only accepted if annotation processing is explicitly requested?

error: Class names are only accepted if annotation processing is explicitly requested in java: solution. This error occurs when you try to compile your java program and forgot to include . java extension with javac command in CMD.


8 Answers

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.

like image 66
aioobe Avatar answered Oct 06 '22 08:10

aioobe


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 by mistake after compiling again use javac for running a program.

like image 33
c_bfx Avatar answered Oct 06 '22 08:10

c_bfx


I was stumped by this too because I was including the .Java extension ... then I noticed the capital J.

This will also cause the "annotation processing" error:

javac myclass.Java 

Instead, it should be:

javac myclass.java 
like image 41
Tom Warfield Avatar answered Oct 06 '22 08:10

Tom Warfield


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).

like image 36
Yong Yuan Avatar answered Oct 06 '22 07:10

Yong Yuan


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.

like image 33
joshgoldeneagle Avatar answered Oct 06 '22 08:10

joshgoldeneagle


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

like image 34
David Miller Avatar answered Oct 06 '22 08:10

David Miller


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

Put this in a file called Main.java:

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

Then compile it like this:

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

It's because you didn't 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 $

Slap your forehead now and grumble that the error message is so cryptic.

like image 41
Eric Leschinski Avatar answered Oct 06 '22 07:10

Eric Leschinski


Perhaps you may be compiling with file name instead of method name....Check once I too made the same mistake but I corrected it quickly .....#happy Coding

like image 20
Sai Saran Avatar answered Oct 06 '22 07:10

Sai Saran