[英]Error: Could not find or load main class com.lara.CoffeeTest
when I am trying to run this code I am getting 当我尝试运行此代码时,
Error: Could not find or load main class com.lara.CoffeeTest 错误:找不到或加载主类com.lara.CoffeeTest
can anybody tell me the reason 有人可以告诉我原因吗
class Coffee {
int size;
}
public class CoffeeTest {
public static void main(String[] args) {
Coffee drink= new Coffee();
drink.size=2;
System.out.println(drink.size);
}
}
java classpath
doesn't contain your CoffeeTest.class file. java classpath
不包含您的CoffeeTest.class文件。 java
adds the current directory to the classpath by default unless there is CLASSPATH
variable defined in the environment. 除非在环境中定义了CLASSPATH
变量,否则java
默认将当前目录添加到类路径。 You can make it work by executing the following 您可以通过执行以下命令使其工作
Change to the directory where 'com' directory resides and execute 转到“ com”目录所在的目录并执行
//if CLASSPATH variable set in environment
java -cp . com.lara.CoffeeTest
or 要么
java com.lara.CoffeeTest
provided you have compiled and .class files are present with the same package structure as that of source. 前提是您已编译,并且.class文件与源文件具有相同的包结构。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.