Class names are only accepted if annotation processing is explicitly requested ошибка

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?

ROMANIA_engineer's user avatar

asked Feb 21, 2011 at 7:15

user513164's user avatar

1

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.

answered Feb 21, 2011 at 7:23

aioobe's user avatar

aioobeaioobe

411k112 gold badges807 silver badges825 bronze badges

4

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 

luk2302's user avatar

luk2302

54.5k23 gold badges97 silver badges136 bronze badges

answered Aug 30, 2013 at 21:00

Tom Warfield's user avatar

0

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

answered Jun 6, 2016 at 20:17

Yong Yuan's user avatar

Yong YuanYong Yuan

1111 silver badge3 bronze badges

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.

answered Mar 16, 2015 at 6:14

joshgoldeneagle's user avatar

joshgoldeneaglejoshgoldeneagle

4,6162 gold badges22 silver badges30 bronze badges

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

answered Sep 1, 2017 at 21:50

David Miller's user avatar

0

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.

xlm's user avatar

xlm

6,68414 gold badges52 silver badges55 bronze badges

answered Nov 9, 2015 at 13:42

c_bfx's user avatar

c_bfxc_bfx

771 silver badge9 bronze badges

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.

answered Sep 18, 2014 at 18:57

Eric Leschinski's user avatar

Eric LeschinskiEric Leschinski

146k95 gold badges412 silver badges332 bronze badges

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 …..#happy Coding

Eric Aya's user avatar

Eric Aya

69.4k35 gold badges181 silver badges252 bronze badges

answered Apr 23, 2018 at 10:53

Sai Saran's user avatar

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 FilesJavajdk1.8.0_191bin»
but in my OS work only this «C:Program FilesJavajdk1.8.0_191binjavac.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:UsersuserIdeaProjectsappsrc.
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

answered Apr 2, 2019 at 16:58

Mr tintin's user avatar

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.

answered Jun 15, 2019 at 6:21

Avnish's user avatar

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

answered Dec 20, 2020 at 14:28

Vladi's user avatar

VladiVladi

1,58217 silver badges29 bronze badges

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

answered Apr 19, 2020 at 10:11

kiran's user avatar

kirankiran

257 bronze badges

Table of Contents

  • Problem: class names are only accepted if annotation processing is explicitly requested
  • Solution: class names are only accepted if annotation processing is explicitly requested

In this post, we will see how to resolve class names are only accepted if annotation processing is explicitly requested
in java.

You will get this error when you are trying to compile java program without .java extension.

Let’s reproduce this issue with the help of an example:

package org.arpit.java2blog;

public class HelloWorldExample {

    public static void main(String[] args) {

        System.out.println(«Hello world»);

    }

}

When we will compile the above class with javac as below:

C:UsersArpitDesktopjavaPrograms>javac HelloWorldExample
error: Class names, ‘HelloWorldExample’, are only accepted if annotation processing is explicitly requested
1 error

As you can see got error:class names are only accepted if annotation processing is explicitly requested because we did not add .java suffix in HelloWorldExample.

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.

C:UsersArpitDesktopjavaPrograms>javac HelloWorldExample.java

C:UsersArpitDesktopjavaPrograms>

As you can see, we did not get any error now.

It may also happen if you are doing improper capitalization of .java extension while compiling.

C:UsersArpitDesktopjavaPrograms>javac HelloWorldExample.Java
error: Class names, ‘HelloWorldExample.Java’, are only accepted if annotation processing is explicitly requested
1 error

If you notice, filename should be HelloWorldExample.java rather than HelloWorldExample.Java.
That’s all about how to fix error:class names are only accepted if annotation processing is explicitly requested.

This error message indicates that you are trying to use a class name in a source code file that is not being processed by the Java compiler.

There are a few potential causes for this error:

  1. You may be trying to use a class name as a variable name or in some other context where it is not allowed. Make sure that you are not using a class name where a variable or function name is expected.

  2. You may be trying to use a class name that is not in your classpath. Make sure that the class you are trying to use is properly imported or that its fully qualified name is used.

  3. You may have forgotten to enable annotation processing. Annotation processing is a feature of the Java compiler that allows you to generate additional source code or resources based on annotations in your source code. If you are using annotations and have not explicitly enabled annotation processing, you will see this error. To enable annotation processing, you can use the -processor command line option or the apt tool.

I hope this helps! Let me know if you have any questions or if you need further assistance.

Contents of page >

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

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

This error occurs when you try to compile your java program and forgot to include .java extension with javac command in CMD.

Let’s take an example >

First let’s write java class >

public class FirstProgram {

   public static void main(String[] args) {

          System.out.println(«This is my first Java Program»);

   }

}

Let’s say above code in file =  E:workspaceFirstProgram.java

Go to CMD and type below commands >

C:Usersankitmittal01>e:

E:>cd E:workspace

E:workspace>javac FirstProgram

error: Class names, ‘FirstProgram’, are only accepted if annotation processing is explicitly requested

1 error

Now, let’s solve the problem (error: Class names, ‘FirstProgram’, are only accepted if annotation processing is explicitly requested) by including .java extension with javac command in CMD.

E:workspace>javac FirstProgram.java

E:workspace>java FirstProgram

This is my first Java Program

E:workspace>

As soon as javac FirstProgram.java is called .class file is formed. (.class file contains bytecode)

Directory of .class file = E:workspaceFirstProgram.class

when java FirstProgram is called it executes the .class file and output of program “This is my first Java Program” is printed in CMD.

Having any doubt? or you you liked the tutorial! Please comment in below section.

RELATED LINKS>

Writing and executing first java program through CMD in windows, Setting up ECLIPSE in java, Directory of .class file

Java tutorial — Advantage, Where is java used in real world, platform independent language

Interface in java — Multiple inheritance, Marker interfaces, When to use interface practically, 12 features

Abstract class in java — When to use abstract class or interface practically, 10 features

Constructor in java — Constructor chaining, access modifiers with constructors, constructor overloading, exception thrown, constructors are not inherited

Fix Class Names Are Only Accepted if Annotation Processing Is Explicitly Requested in Java

This tutorial highlights the reasons and guides how to fix this error using a sample Java program.

Fix Class Names, 'test.java', Are Only Accepted If Annotation Processing Is Explicitly Requested in Java

Before moving towards the solution, let’s write the following Java program to understand the possible reasons for having this error.

Example Code:

//test class
public class test {
    //main()
    public static void main(String[] args) {
        //print message
        System.out.println("Hello, this is just a test program.");
    }//end main()
}//end test class

Now, use the command given below to compile the Java code.

javac writeYourFileNameHere

Here, we will get the error saying class names, 'test.java', are only accepted if annotation processing is explicitly requested (test.java is our file name, you will see your file name there).

Why is it so? As per Java documentation, there are two possible reasons for having this error.

  1. We forget to add the .java suffix at the end of the file name.
  2. We use improper capitalization of the .java suffix. For instance, we compile as javac test.Java

You can find both commands in the following screenshot.

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

How to resolve this error?

The solution for this compile time error is very simple. We only need to add the .java suffix (all in small letters).

Let’s do it by using the sample code below.

Example Code:

//test class
public class test {
    //main()
    public static void main(String[] args) {
        //print message
        System.out.println("Hello, this is just a test program.");
    }//end main()
}//end test class

This time, we compiled the code using javac test.java. If it compiles successfully, we use the java test command to run the program (don’t forget to write your own file’s name).

Both of these commands are demonstrated in the following screenshot.

OUTPUT:

class names are only accepted if annotation processing is explicitly requested - solution

  • Class jformfieldlist not found ошибка джумла
  • Clash royale ошибка подключения к серверу
  • Clas 24ff ошибка 302
  • Clack ws1tc ошибка e4
  • Clack ws1ci ошибка 102