- javac error: Class names are only accepted if annotation processing is explicitly requested
- Solution 2 — Java
- Solution 3 — Java
- Solution 4 — Java
- Solution 5 — Java
- Solution 6 — Java
- Solution 7 — Java
- Solution 8 — Java
- Solution 9 — Java
- Solution 10 — Java
- Solution 11 — Java
- Solution 12 — Java
- [Solved] Class names are only accepted if annotation processing is explicitly requested
- Problem: class names are only accepted if annotation processing is explicitly requested
- Solution: class names are only accepted if annotation processing is explicitly requested
- Was this post helpful?
- Share this
- Related Posts
- Author
- Related Posts
- [Fixed] Unsupported class file major version 61 in Java
- [Fixed] java.lang.ClassCastException: java.util.Arrays$ArrayList cannot be cast to java.util.ArrayList
- [Fixed] java.util.HashMap$Values cannot be cast to class java.util.List
- [Fixed] Unable to obtain LocalDateTime from TemporalAccessor
- Fix Class Names Are Only Accepted if Annotation Processing Is Explicitly Requested in Java
- Fix Class Names, ‘test.java’, Are Only Accepted If Annotation Processing Is Explicitly Requested in Java
- Related Article — Java Error
javac error: Class names are only accepted if annotation processing is explicitly requested
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
> 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.
Solution 2 — Java
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:
Solution 3 — Java
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).
Solution 4 — Java
The error «Class names are only accepted if annotation processing is explicitly requested» can be caused by one or more of the following:
- Not using the .java extension for your java file when compiling.
- Improper capitalization of the .java extension (i.e. .Java) when compiling.
- Any other typo in the .java extension when compiling.
- 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.
Solution 5 — Java
I learned that you also can get this error by storing the source file in a folder named Java
Solution 6 — Java
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.
Solution 7 — Java
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.
Solution 8 — Java
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
Solution 9 — Java
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
Solution 10 — Java
To avoid this error, you should use javac command with .java extension.
Solution 11 — Java
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
java -cp FILENAME.jar package.Java-Main-File-Name-Class
Edited : after puting in Pom file declar the main to run the code :
Solution 12 — Java
If you compile multiple files in the same line, ensure that you use javac only once and not for every class file.
[Solved] 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.
Problem: class names are only accepted if annotation processing is explicitly requested
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:
When we will compile the above class with javac as below:
C:\Users\Arpit\Desktop\javaPrograms>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.
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:\Users\Arpit\Desktop\javaPrograms>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 .
Was this post helpful?
Share this
Related Posts
Author
Related Posts
[Fixed] Unsupported class file major version 61 in Java
Table of ContentsReason for Unsupported class file major version 61 in JavaSolution for Unsupported class file major version 61 in JavaAndorid studio/Intellij Idea with gradleAny other scenario In this post, we will see how to fix Unsupported class file major version 61 in Java. Reason for Unsupported class file major version 61 in Java You […]
[Fixed] java.lang.ClassCastException: java.util.Arrays$ArrayList cannot be cast to java.util.ArrayList
Table of ContentsReason for java.lang.ClassCastException: java.util.Arrays$ArrayList cannot be cast to java.util.ArrayListFixes for java.lang.ClassCastException: java.util.Arrays$ArrayList cannot be cast to java.util.ArrayListUse ArrayList’s constructorAssign Arrays.asList() to List reference rather than ArrayList In this post, we will see how to fix java.lang.ClassCastException: java.util.Arrays$ArrayList cannot be cast to java.util.ArrayList. ClassCastException is runtime exception which indicate that code has tried to […]
[Fixed] java.util.HashMap$Values cannot be cast to class java.util.List
Table of ContentsWhy HashMap values cannot be cast to list?Fix for java.util.HashMap$Values cannot be cast to class java.util.List In this post, we will see how to fix error java.util.HashMap$Values cannot be cast to class java.util.List. Why HashMap values cannot be cast to list? HashMap values returns java.util.Collection and you can not cast Collection to List […]
[Fixed] Unable to obtain LocalDateTime from TemporalAccessor
Table of ContentsUnable to obtain LocalDateTime from TemporalAccessor : ReasonUnable to obtain LocalDateTime from TemporalAccessor : FixLocalDate’s parse() method with atStartOfDay()Use LocalDate instead of LocalDateTime In this article, we will see how to fix Unable to obtain LocalDateTime from TemporalAccessor in Java 8. Unable to obtain LocalDateTime from TemporalAccessor : Reason You will generally get […]
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.
//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).
- We forget to add the .java suffix at the end of the file name.
- 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.
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.
//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.
Mehvish Ashiq is a former Java Programmer and a Data Science enthusiast who leverages her expertise to help others to learn and grow by creating interesting, useful, and reader-friendly content in Computer Programming, Data Science, and Technology.