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

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

王林
王林forward
2019-11-26 15:03:462827browse

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");	
	}
}

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

TestTwo.java

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

运行的代码:

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

输入 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

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

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!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete