Beginner Java, today try compiling and running Hello.java in the command line interface
(File current directory ..... \src\chapter1)
1 PackageChapter1;2 3 Public classHello {4 Public Static voidMain (string[] args) {5 if(args.length==0)6System.out.println ("hello!");7 Else{8 for(inti=0;i<args.length;i++)9 System.out.println (Args[i]);Ten } One } A}
You encounter an error prompt:
Error: The main class Hello is not found or cannot be loaded
This issue was addressed through access to information.
Cause of the problem:
The concept of package in Java is not clear. This procedure is the previous editing test in Eclipse, direct copy to use, so that the program segment left redundant package declaration
1 Package chapter1;
The Hello class puts it under the Chapter1 package, while the environment variable classpath sets the current directory, the current directory is ... src \ Chapter1 , the actuator will find chapter1 this package in the current directory, but actually there is no chapter1 under. So the class Hello is not found.
Workaround:
1. Remove the package statement
2, in the current directory and then create a chapter1 folder, put the source files in. (... \src\chapter1\chapter1)/runtime fallback to the previous level directory (...\src)
Note that compiling is sure to be in the path of the file (...\src\chapter1), otherwise there will be an error.
same error other possible scenarios: Check that the environment variables are correct
"Error: The main class could not be found or could not be loaded" when compiling and running Java programs on the command line