Thursday, February 8, 2018

java - Idea error-Could not find or load main class



I was just running the basic helloworld program, as follows:



public class test {


public static void main(String[] args) {
System.out.println("Hello, World");
}
}


After I typed "javac src\test.java" to compile it, and it compiled successfully, then I typed "java src\test", and it showed



">"C:\Program Files\Java\jdk1.8.0_65\bin\java.exe" src\test



Error: Could not find or load main class src\test".



So I set my path to



 ".;%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin" and classpath to 
".;%JAVA_HOME%\lib;%JAVA_HOME%\lib\tools.jar" so I think there's nothing wrong here..



And I don't know what's going on here... Any advice would be appreciated.


Answer



Run



java -cp src test


-cp src tells Java to look in the src folder for classes. test is the name of the class to run.



Note that the java command takes a class name, not a file name.



No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...