java.util.MissingResourceException
Asked Answered
B

6

6

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

Bimolecular answered 14/4, 2010 at 10:19 Comment(1)
Can you confirm whether the file is in your classpath at runtime? Perhaps provide the code and file layout you're using.Lawton
L
13

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"

Leucippus answered 14/4, 2010 at 10:27 Comment(1)
I had the same error, my properties files were located in the same package as the class file, specifying the fully qualified name (package name + properties file name) worked with meIatrics
S
4

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");
Spaceband answered 21/11, 2012 at 8:38 Comment(0)
B
2

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.

Biographer answered 26/7, 2016 at 13:0 Comment(0)
M
1

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());
Marcenemarcescent answered 14/4, 2010 at 10:31 Comment(0)
L
1

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

Lail answered 21/10, 2014 at 22:19 Comment(0)
G
0

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

Ganglion answered 14/4, 2010 at 10:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.