gpt4 book ai didi

java.util.MissingResourceException--如何解决?检查类路径并使用限定名称

转载 作者:行者123 更新时间:2023-12-01 22:22:09 25 4
gpt4 key购买 nike

这个错误一直困扰着我。我似乎无法理解为什么 Eclipse 无法读取就在那里的资源。我已经在“配置包含”对话框中检查了类路径。我还使用该文件的完全限定名称。

AutomateWaveClose
src
package DBCommon
DBConfig.properties

(由于信誉不足,无法粘贴图片)

代码中的文件名如下:

private static final String FILENAME="AutomateWaveClose.src.DBConfig.properties";

ResourceBundle DBconfig = ResourceBundle.getBundle(FILENAME);

我得到的异常(exception)是:

我不明白为什么会出现语言环境 en_US,因为我在调用此方法时仅使用基本名称。任何帮助表示赞赏。我浏览过类似的相关帖子,但它们对我没有帮助。

Exception in thread "main" java.util.MissingResourceException: Can't find bundle for base name AutomateWaveClose.src.DBConfig.properties, locale en_US at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1427) at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1250) at java.util.ResourceBundle.getBundle(ResourceBundle.java:705) at DBCommon.GetAS400Connection.main(GetAS400Connection.java:25)

最佳答案

从文件名中删除“.properties”。

编辑:以下是 ResourceBundle.getBundle 的具体信息.

getBundle then iterates over the candidate bundle names to find the first one for which it can instantiate an actual resource bundle. It uses the default controls' getFormats method, which generates two bundle names for each generated name, the first a class name and the second a properties file name. For each candidate bundle name, it attempts to create a resource bundle:

First, it attempts to load a class using the generated class name. If such a class can be found and loaded using the specified class loader, is assignment compatible with ResourceBundle, is accessible from ResourceBundle, and can be instantiated, getBundle creates a new instance of this class and uses it as the result resource bundle. Otherwise, getBundle attempts to locate a property resource file using the generated properties file name. It generates a path name from the candidate bundle name by replacing all "." characters with "/" and appending the string ".properties". It attempts to find a "resource" with this name using ClassLoader.getResource. (Note that a "resource" in the sense of getResource has nothing to do with the contents of a resource bundle, it is just a container of data, such as a file.) If it finds a "resource", it attempts to create a new PropertyResourceBundle instance from its contents. If successful, this instance becomes the result resource bundle.

关于java.util.MissingResourceException--如何解决?检查类路径并使用限定名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29520517/

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