天天看點

javac: file not found: polymorphism.music.Music.java or Error: Could not find or load main class pol

An example of what a 

java

 command should look like:

java -Xmx100m com.acme.example.ListUsers fred joe bert
           

The above is going to cause the 

java

 command to do the following:

  1. Search for the compiled version of the 

    com.acme.example.ListUsers

     class.
  2. Load the class.
  3. Check that the class has a 

    main

     method with signature, return type and modifiers given by 

    public static void main(String[])

    . (Note, the method argument's name is NOT part of the signature.)
  4. Call that method passing it the command line arguments ("fred", "joe", "bert") as a 

    String[]

    .

Q1. javac: file not found: polymorphism.music.Music.java 

A1: instead use

$ javac polymorphism/music/Music.java
           

also use absolute classpath, for example,

javac ~/user/polymorphism/music/Music.java

Q2: Error: Could not find or load main class polymorphism.music.Music

A1: be sure already has Music.class, then use

$ java polymorphism.music.Music
           

or 

java polymorphism/music/Music
           

If you want use javac/java in current directory, you need modify source code. Remove package sentences and some comments in exmaples code.

refereces:

1. https://stackoverflow.com/questions/18093928/what-does-could-not-find-or-load-main-class-mean 

繼續閱讀