1
The code below does not compile:
package app1;
public class main{
public static void main(String args[]){
System.out.println("Hello World!");
}
}
The following message appears in the terminal:
Error: Could not find or load main class main
the file main.java
is saved in folder app1
. I’m compiling through the terminal at Manjaro.
I don’t understand, when I compile in the IDE (either Netbeans or Eclipse) the code runs, but the terminal goes wrong. I appreciate the attention already.
Command line to run which you are testing?
– Jefferson Quesado
javac main.java [enter] java main [enter]
– Henrique Marques
The way you are running, Java would expect you to be without a package in the class. You said it was inside the folder
app1
, right? Try tojava -classpath ../ main
. The-classpath
is teaching Java which way it should go after the classes. How you are inside the folderapp1
(you said above), then the root is above that, so the root is in..
– Jefferson Quesado