• Register
0 votes
273 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

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 48 views
48 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 stewart 4k points
0 votes
2 answers 65 views
65 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 57 views
57 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 jwilliam 3.9k points
0 votes
1 answer 38 views
38 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 jwilliam 3.9k points