gpt4 book ai didi

java - 如何调试 Java 中的 ClassLoader 找不到文件

转载 作者:行者123 更新时间:2023-12-02 00:42:07 25 4
gpt4 key购买 nike

我正在尝试将 JavaHelp 系统集成到使用 Eclipse 开发的项目中。我从 example 中提取了以下代码:

private HelpSet getHelpSet(String helpsetfile) {
HelpSet hs = null;
ClassLoader cl = this.getClass().getClassLoader();

try {
URL hsURL = HelpSet.findHelpSet(cl, helpsetfile);

hs = new HelpSet(null, hsURL);
} catch(Exception ee) {
System.out.println("HelpSet: "+ee.getMessage());
System.out.println("HelpSet: "+ helpsetfile + " not found");
}
return hs;
}


HelpSet hs = getHelpSet("doc/Sample.hs.txt");

找不到帮助集文件,但存在 (doc/Sample.hs.txt)。我认为路径或类加载器使用有问题,但我无法弄清楚问题是什么。有人有想法吗?

提前致谢

最佳答案

hs = new HelpSet(null, hsURL);

HelpSet-Class 获取的是 null 而不是 ClassLoader 实例,因此它无法加载任何内容。这应该是:

hs = new HelpSet(cl, hsURL);

关于java - 如何调试 Java 中的 ClassLoader 找不到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6061743/

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