gpt4 book ai didi

java.lang.NoClassDefFoundError

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:59:48 25 4
gpt4 key购买 nike

我正在学习 Java,但在运行示例程序时遇到了问题。

我有两个文件:

好狗.java:

    class GoodDog {
private int size;
public int getSize() {
return size;
}

public void setSize(int s) {
size = s;
}

void bark() {
if (size > 60) {
System.out.println("Wooof! WoooF!");
} else if (size > 14) {
System.out.println("Ruff! Ruff!");
} else {
System.out.println("Yip! Yip!");
}
}
}

GoodDogTestDrive.java:

    class GoodDogTestDrive {
public static void main (String[] args) {
GoodDog one = new GoodDog();
one.setSize(70);
GoodDog two = new GoodDog();
two.setSize(8);
System.out.println("Dog one: " + one.getSize () );
System.out.println("Dog two: " + two.getSize () );
one.bark();
two.bark();
}
}

它们的打印方式与书中的完全一致,并且编译没有问题。当我尝试运行 GoodDogTestDrive 时,我得到了这个:

nephi-shields-mac-mini:/Developer/MyProjects/GoodDog nephishields$ java GoodDogTestDrive.class
java.lang.NoClassDefFoundError: GoodDogTestDrive/class
Exception in thread "main" nephi-shields-mac-mini:/Developer/MyProjects/GoodDog nephishields$

我做错了什么?

最佳答案

不要在命令中包含 .class:

java GoodDogTestDrive

关于java.lang.NoClassDefFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5587585/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com