Thursday, 8 February 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

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...