开发者

java.util.MissingResourceException

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 开发者_如何学Pythonam using RSA7 as IDE, is there any setting problem? any suggestions are welcome.....

Thanks a lot in advance


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"


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");


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.


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());


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜