gpt4 book ai didi

java - 在 Eclipse 中执行程序时找不到类

转载 作者:太空宇宙 更新时间:2023-11-04 13:57:09 25 4
gpt4 key购买 nike

下面是示例java代码

class Candy {
static {
print("Loading candy");
}
}

class Gum {
static {
print("Loading Gum");
}
}

class Cookie {
static {
print("Loading Cookie");
}
}


public class SweetShop {
public static void main(String[] args) {
print("inside main");
new Candy();
print("after creating candy");
try{
Class.forName("Gum");
}
catch(ClassNotFoundException e) {
print("could not find gum class");
}
print("After Class.forName(\"Gum\")");
new Cookie();
print("After creating Cookie");
}
}

当执行时,我总是会输出为

inside main

Loading candy

after creating candy

could not find gum class

After Class.forName("Gum")

Loading CookiePlease provide some help.After creating Cookie

最佳答案

如果您有软件包,请尝试此操作:

   Class.forName("package_name.Gum");

关于java - 在 Eclipse 中执行程序时找不到类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29706852/

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