• Register
0 votes
607 views

Problem:

I face this error when I compile my java program:

error: Class names, 'MyDevices', are only accepted if annotation

processing is explicitly requested

1 error

Here is the javac command:

javac -cp /home/myname/Desktop/JCuda-All-0.3.2-bin-linux-x86_64 MyDevices

How can I compile my program?

7 5 2
3,870 points

Please log in or register to answer this question.

2 Answers

0 votes

Solution :

I had also faced the similar issue in the recent past. I did lot of research on it and found the solution on it. This is the very common problem with the people getting started.

Your error "Class names are only accepted if annotation processing is explicitly requested" can be caused by one or more of the below:

  1. Not using the .java extension for the java file when compiling.
  1. Improper capitalization of your .java extension (i.e. .Java) when compiling.
  1. Any other typo in your .java extension when compiling.
  1. When compiling and running at the same time and forgetting to use '&&' to concatenate the two commands (example. javac Hangman.java java Hangman). It took me like 30 minutes to figure this out, which I noticed by running my compilation and the running the program separately, which of course worked perfectly fine for me.

This may not be the complete list of the causes to this error, but these are the causes that I am aware of so far.

9 7 4
38,600 points
0 votes

Solution:

You at least require to include 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 just received in case annotation processing is bluntly requested

In case you accepts this error, you forgot to add the .java suffix at the time compiling the program. Keep in mind, the command is javac HelloWorldApp.java not javac HelloWorldApp.

Further, in your second javac-example, (in which you really added .java) you require to add the all required .jar-files needed for compilation.

This will also happened the "annotation processing" error:

javac myclass.Java 

Instead, it must be:

javac myclass.java 

Employing javac ClassName.java to compile the program, then employ java ClassName to execute the compiled code. You can't mix javac with the ClassName just (without the java extension).

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

Hence in case you by mistake after compiling again employ javac for running a program.

This error happens at the time you attempt to compile your java program and forgot to add .java extension with javac command in CMD.

example >

write java class >

public class FirstProgram {
    public static void main(String[] args) {
           System.out.println("This is my first Java Program");
    }
}

Go to CMD and type below commands >

C:\Users\ankitmittal01>e:

E:\>cd E:\workspace

E:\workspace>javac FirstProgram
error: Class names, 'FirstProgram', are only accepted if annotation processing is explicitly requested
1 error

Presently, let’s solve the problem (error: Class names, 'FirstProgram', are just received in case annotation processing is explicitly requested) by adding .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 comprise bytecode)

Hence you would run:

javac PezDispenser.java

 

10 6 4
31,120 points

Related questions

1 vote
1 answer 86 views
86 views
Problem : I am very new to Java Programming. I am often facing below error if I try to compile the Java program: error: Class names, 'MyDevices', are only accepted if annotation processing is explicitly requested 1 error Please find below my Java code. I am trying ... command: javac -cp /home/stewart/Desktop/JCuda-All-0.3.2-bin-linux-x86_64 MyDevices How should I compile my above Java program?
asked Apr 28, 2020 stewart 4k points
0 votes
1 answer 12 views
12 views
I get this error when I compile my java program. How do I compile this program?
asked Dec 14, 2020 TeamScript 11.1k points
0 votes
1 answer 16 views
0 votes
2 answers 102 views
102 views
Problem : Here I want to copy all the objects in the List with object1 to a list with object2: Following is my code snip: List<EmployeeAmManegmentModel> AM = employee.amEmployeeDeatails(); List<EmployeeRmManegmentModel> RM = employee.rmEmployeeDeatails(); List< ... Long status; private String employeeType; How can I copy the result from one list of different object type to another?
asked Dec 3, 2019 alecxe 7.5k points
0 votes
1 answer 74 views
74 views
Problem : I have the below two classes public class A {     A() {         System.out.println("A");     } } class B extends A {     B() {         System.out.println("B");     } } And after that running 1 A c = new B(); or 2 B c = new B( ... glance, in either of the scenario, I would assume that only a B constructor would be called and so the only output would be B But this is completely wrong.
asked Jan 23, 2020 jwilliam 3.9k points
0 votes
1 answer 22 views
22 views
I have installed java in my Cent OS 7 machine using the command yum install java. But I am unable to compile a class using javac. Do I need to install any other additional packages to run the javac command?
asked Jun 23, 2020 adamSw 11.3k points
0 votes
1 answer 5 views
5 views
java file with a default class access specifier get compiled?
asked 1 day ago TeamScript 11.1k points
0 votes
1 answer 51 views
51 views
Problem : In Java, I want to have something as below : class MyClazz<T> {  static void doIt(T object) {    // More code  } } But I face below error &ldquo;Cannot make a static reference to the non-static type T&rdquo; I am unable to understand ... about a subject. Could someone clarify if such the use is possible, by the similar manner? Also, why was my original attempt went unsuccessful?
asked Jan 21, 2020 jwilliam 3.9k points
0 votes
1 answer 1.7K views
1.7K views
Problem : I am currently working on the project and i am getting the error as below : "Implicit super constructor MyPerson() is undefined. Must explicitly invoke another constructor" But I am unable to understand it. Below is my MyPerson class: public class ... and just giving it an instructor variable as below : public class MyStudent extends MyPerson { public MyStudent(String myInstructor) { } }
asked Dec 16, 2019 alecxe 7.5k points
0 votes
1 answer 338 views
338 views
Problem : I am getting bellow error while I'm trying to use visual studio code for Java. this version of the java runtime only recognizes class file versions up to 52.0
asked Oct 19, 2019 peterlaw 6.9k points