Javac Error: Class Names Are Only Accepted If Annotation Processing Is Explicitly Requested

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

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.

Class names, 'Introductions', are only accepted if annotation processing is explicitly requested

There are two different commands to compile Java programs and run Java programs. You're receiving an error that means that the command to compile the program (javac) has received arguments that don't include the .java suffix, as mentioned in other questions about this error.

It sounds, however, like you are compiling correctly, using javac Introductions.java. Your problem is actually in the second step, running the program. Running javac Introductions tells Java you want to compile again, and so it correctly points out that you forgot the extension.

But you're not wanting to compile a second time; you want to run it! That uses java instead of javac.

To compile: javac Introductions.java

To run: java Introductions

See also How do I run a Java program from the command line on Windows? (though this isn't really Windows-specific).

Cannot run compiled java class, error: Class names are only accepted if annotation processing is explicitly requested

You're calling javac, the compiler, to run your program. You run the program via java, not javac. Your second command should be:

java -cp DAT.jar;Exceptions.jar TestQueueString

Note no "c" on "java", and I've added the classpath since you added it when compiling.


Re your edit: The problem there is exactly what it says it is: It can't find the class TestQueueString. I can think of two possible reasons for this:

  1. The current directory is not in your classpath; try:

    java -cp DAT.jar;Exceptions.jar;. TestQueueString

    (Note the ;. at the end of the classpath.)

  2. Your TestQueueString.java file has a package declaration. If so, you need to tell java the full name of the class (e.g., foo.TestQueueString not just TestQueueString if it were in package foo), and the file has to be in the right place relative to the current working directory (again assuming package foo, the class file would have to be in a foo subdirectory).

Given the error message you've quoted, and assuming you're using an up-to-date version of Java, I'd guess #1, since #2 would say something like

Exception in thread "main" java.lang.NoClassDefFoundError: TestQueueString (wrong name: foo/TestQueueString)

...(note the "wrong name" bit) if the package were foo.

Error in code - Class names are only accepted if annotation

You seem to have translated:

do repeat stmt
until A[ j ] ≤ x;

into

do {
stmt;
} while (A[j] >= x);

This is not correct. The comparison which is the opposite of ≤ would be >, not ≥. Therefore, your comparison when translating from "until" to "while" would use > such as while (A[j] > x);.

The other errors in your possible homework are similar and I encourage you to think each translation through carefully on your own.



Related Topics



Leave a reply



Submit