Home > Java > JavaBase > body text

Running the java class file from the command line prompts that the main class cannot be found or cannot be loaded.

王林
Release: 2019-11-26 15:03:46
forward
2922 people have browsed it

Running the java class file from the command line prompts that the main class cannot be found or cannot be loaded.

问题如下

TestOne.java

package moon.star;
public class TestOne {
	public void fTestOne() {
  		System.out.println("I an a method In TestOne class");	
	}
}
Copy after login

相关学习视频推荐:java视频教程

TestTwo.java

package moon.star;
public class TestTwo {
	public void fTestTwo() {
  		System.out.println("I an a method In TestTwo class");
 	}
}
Copy after login

运行的代码:

import moon.star.*;
public class Use {	
	public static void main(String args[]) {
  		TestOne a = new TestOne();
  		a.fTestOne();
  		TestTwo b = new TestTwo();
  		b.fTestTwo();
 	}
}
Copy after login

输入 javac Use.java编译没有问题,输入java Use运行时却出错!

Running the java class file from the command line prompts that the main class cannot be found or cannot be loaded.

问题解决

命令行输入set classpath=C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\Jerry.jar;.;E:\1000

来指明我的moon.star包的位置,位置是E:\1000,即包名为moon.star的类的字节码存放在E:\1000\moon\star目录中。用户可以更新classpath的设置。

C:\Users\前世药师\Desktop>set classpath=C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\Jerry.jar;.;E:\1000
Copy after login

问题解决,成功运行结果图如下:

Running the java class file from the command line prompts that the main class cannot be found or cannot be loaded.

想了解更多相关问题,可以访问:java语言入门

The above is the detailed content of Running the java class file from the command line prompts that the main class cannot be found or cannot be loaded.. For more information, please follow other related articles on the PHP Chinese website!

source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template