Java cannot find class file, while javap can

I have compiled a class (called Test.class) using the Java ASM library . I decided to give it a try and make sure that I compiled the class correctly by trying to run it with the "java" command.

However, when I did this, I received the message "Could not find or load main test case". I thought it was weird since the class is inside the current working directory (I've also tried passing in "." As the classpath, to no avail). Then I tried to parse it with "javap" which worked fine, which is weird, since if javap can find the class file, then surely java should be able to as well?

Here is my command line input and output:

$ javap -c Test

Compiled from "Test.ash" 
public class Test
{   
  public Test();
    Code:
     0: aload_0
     1: invokespecial #9 // Method "java.lang.Object"."<init>":()V
     4: return

  public static void main(java.lang.String[]);
    Code:
     0: return
}

      

$ java Test

Error: Could not find or load test of main class

$ java Test.class

Error: Could not find or load test of main class

$ java -cp. Test

Error: Could not find or load test of main class

$ java -cp. Test.class

Error: Could not find or load test of main class

What could be wrong? I could compile the class incorrectly, but then surely javap will complain as well as java and the javap output looks correct.

+3


source to share


1 answer


I found the problem, I was not replacing dots in the cool superclass name with a forward slash.



Thus, the class had the superclass "java.lang.Object" and not "java / lang / Object" which is required.

+3


source







All Articles