java.util.MissingResourceException

发布于 2024-08-29 00:45:00 字数 615 浏览 5 评论 0原文

我在运行应用程序时遇到异常。该应用程序读取abc.properties文件,

Exception in thread "main" java.util.MissingResourceException: Can't find bundle for base name abc, locale en_US
    at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:853)
    at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:822)
    at java.util.ResourceBundle.getBundle(ResourceBundle.java:566)
    at com.ibm.dst.DailyExtract.getResourceBundle(DailyExtract.java:104)
    at com.ibm.dst.DailyExtract.main(DailyExtract.java:131)

abc.properties文件驻留在工作空间中。 我使用RSA7作为IDE,有什么设置问题吗? 欢迎任何建议......

提前非常感谢

I am getting below exception while running an application. This application read abc.properties file,

Exception in thread "main" java.util.MissingResourceException: Can't find bundle for base name abc, locale en_US
    at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:853)
    at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:822)
    at java.util.ResourceBundle.getBundle(ResourceBundle.java:566)
    at com.ibm.dst.DailyExtract.getResourceBundle(DailyExtract.java:104)
    at com.ibm.dst.DailyExtract.main(DailyExtract.java:131)

abc.properties file reside at the workspace.
I am using RSA7 as IDE, is there any setting problem?
any suggestions are welcome.....

Thanks a lot in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

他不在意 2024-09-05 00:45:00

按照这篇文章中的提示,看看您是否犯了其中一个错误,这可能是(从链接复制粘贴):

  1. 这些资源属性文件由类加载器加载,类似于java类。因此,您需要将它们包含在运行时类路径中。

  2. 这些资源具有完全限定资源名称,类似于完全限定类名称,摘录您无法将资源导入到 java 源文件中。为什么?因为它的名称采用字符串的形式。

  3. ResourceBundle.getBundle("config") 告诉类加载器使用默认包(即无包)加载名为“config”的资源。它并不意味着当前包中具有引用类的资源。

  4. ResourceBundle.getBundle("com.heng.scrap.config") 告诉类加载器加载名为“config”且包为“com.heng.scrap”的资源。它的完全限定资源名称是“com.heng.scrap.config”

Follow the hints in this post and see if you made one of those mistakes, which could be (copy pasted from the link):

  1. These resource properties files are loaded by classloader, similar to java classes. So you need to include them in your runtime classpath.

  2. These resources have fully-qualified-resource-name, similar to a fully-qualified-class-name, excerpt you can't import a resource into your java source file. Why? because its name takes the form of a string.

  3. ResourceBundle.getBundle("config") tells the classloader to load a resource named "config" with default package (that is, no package). It does NOT mean a resource in the current package that has the referencing class.

  4. ResourceBundle.getBundle("com.cheng.scrap.config") tells the classloader to load a resource named "config" with package "com.cheng.scrap." Its fully-qualified-resource-name is "com.cheng.scrap.config"

玉环 2024-09-05 00:45:00

您只需要在获取文件时添加包名称

例如,如果您的属性名称是包 abc 中的“ABC.properties”,那么下面的代码将完美运行

ResourceBundle labels = ResourceBundle.getBundle("a.b.c.ABC");

You just need to add the package name while getting the file

For example if your properties name is "ABC.properties" in package a.b.c then the below code will work perfectly

ResourceBundle labels = ResourceBundle.getBundle("a.b.c.ABC");
時窥 2024-09-05 00:45:00

只需将资源文件复制到类文件所在的位置即可。

就我而言,我的目录是:

bin 
  - com 
     - brookf 
        - all my packages here. 

将资源文件复制到 bin 文件夹。

Just copy the resource file over to where your class files are.

In my case my directory was:

bin 
  - com 
     - brookf 
        - all my packages here. 

copy your resource file to the bin folder.

洒一地阳光 2024-09-05 00:45:00

加载本地化内容的属性文件也会受到包命名的影响。如果您将属性文件放在像 org.example.com.foobar 这样的包中,并仅通过其名称 abc 加载它,则必须添加前缀 org.properties 文件。 example.com.foobar 也是如此。如果属性位于不同位置(例如在根目录或另一个子目录中),则必须更改要加载的名称或类路径。

我将属性文件放置在 .java 文件所在的同一位置并使用类似的东西运行良好

private static ResourceBundle RES = ResourceBundle.getBundle(NameOfTheCurrentClass.class.getCanonicalName());

Loading the Properties file for localization stuff is also affected by the package naming. If you put your Properties file in a package like org.example.com.foobar and load it just by its name abc you have to add the prefix org.example.com.foobar, too. If you have the properties at a different location (like in the root directory or in another subdir) you have to change either the name to load or the classpath.

I run fine in placing the properties file in the same location where the .java file is and using something like

private static ResourceBundle RES = ResourceBundle.getBundle(NameOfTheCurrentClass.class.getCanonicalName());
木落 2024-09-05 00:45:00

今天我遇到了同样的问题,我花了一段时间才找到解决方案(我使用 Eclipse 作为 IDE)。我的项目文件夹包含以下路径中的 *.properties-Files:

project/src/strings

由于 strings 是 src 的子文件夹,并且 src 已经在项目的构建路径中(请参阅属性窗口),所以我需要的只是添加一个包含 - *.properties-Files 的模式:

**/*.properties

应该已经有一个 *.java-Files (**/*.java) 的包含模式,

也许您的 IDE 有类似的东西

I had the same issue today and it took me a while until I figured out a fix (I'm using Eclipse as an IDE). My project folder contains the *.properties-Files in the following path:

project/src/strings

Since strings is a sub-folder of src and src is already in the build path of the project (see Property Window), all I needed was to add an Inclusion-Pattern for the *.properties-Files:

**/*.properties

There should be already an Inclusion-Pattern for *.java-Files (**/*.java)

Maybe there is something similar for your IDE

眼波传意 2024-09-05 00:45:00

该文件在您的类路径中吗?如果是,请尝试将其重命名为 abc_en_US.properties

Is the file in your classpath? If it is, try renaming it to abc_en_US.properties

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文