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

13

137

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?

Argumentative answered 21/2, 2011 at 7:15 Comment(1)
ensure your file name ends with .java (lowercase)Locomotive
B
168

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.

Bought answered 21/2, 2011 at 7:23 Comment(4)
that too, but still wouldn't have yielded that particular error I think. Should have yielded a "file not found" or something along those lines.Helgahelge
I would agree. Especially since it is an easy mistake to do (since the .class should be omitted when launching with java).Bought
"Class names, 'HelloWorldApp', are only accepted if annotation processing is explicitly requested". What a stupid way to say file not found. Or what is the error message supposed to refer to? I can only find this fix, but not why the error message is worded like that.Actinomycin
With annotation processing enabled you can generate classes programatically during compilation. So with annotation processing you could in fact compile something even though the file does not exist (i.e. you create the missing parts on the fly). Granted, the error message is misleading. I'll get back to you if I look further into it.Bought
B
29

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 
Bernita answered 30/8, 2013 at 21:0 Comment(0)
T
11

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

Trochal answered 6/6, 2016 at 20:17 Comment(0)
S
7

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.

Saideman answered 16/3, 2015 at 6:14 Comment(0)
H
6

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

Hermaphrodite answered 1/9, 2017 at 21:50 Comment(0)
S
4
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.

Schroeder answered 9/11, 2015 at 13:42 Comment(1)
So what should we use to run the program instead of javac?Dulciana
A
1

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.

Allina answered 18/9, 2014 at 18:57 Comment(1)
you didn't either :D ! you wrote Main without .java in both examples!Dare
T
1

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

Tessitura answered 23/4, 2018 at 10:53 Comment(0)
E
1

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

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

javac DescendingOrder.java <- this work perfectly.

Exonerate answered 15/6, 2019 at 6:21 Comment(0)
R
0

first download jdk from https://www.oracle.com/technetwork/java/javase/downloads/index.html. Then in search write Edit the System environment variables In open window i push bottom called Environment Variables Then in System variables enter image description here Push bottom new In field new variables write "Path" In field new value Write directory in folder bin in jdk like "C:\Program Files\Java\jdk1.8.0_191\bin" but in my OS work only this "C:\Program Files\Java\jdk1.8.0_191\bin\javac.exe" enter image description here press ok 3 times

Start Cmd. I push bottom windows + R. Then write cmd. In cmd write "cd (your directory with code )" looks like C:\Users\user\IdeaProjects\app\src. Then write "javac (name of your main class for your program).java" looks like blabla.java and javac create byte code like (name of your main class).class in your directory. last write in cmd "java (name of your main class)" and my program start work

Rajewski answered 2/4, 2019 at 16:58 Comment(0)
B
0

I created a jar file from a Maven project (by write mvn package or mvn install )

after that i open the cmd , move to the jar direction and then

to run this code the

java -cp FILENAME.jar package.Java-Main-File-Name-Class

Edited : after puting in Pom file declar the main to run the code :

java -jar FILENAME.JAR
Backsaw answered 20/12, 2020 at 14:28 Comment(0)
A
0
  • open your myClass.java directory
  • open cmd there
  • execute

javac myClass.java

  • then

java myClass

Aswarm answered 9/3 at 17:11 Comment(0)
D
-1

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

Incorrect: enter image description here

Correct: enter image description here

Diarchy answered 19/4, 2020 at 10:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.