0
votes

This error has been bugging me a lot. I can't seem to understand why in the world Eclipse can't read this resource which is right there. I have already checked the classpath in the Configure inclusion dialog box. I am also using the fully qualified name for this file.

AutomateWaveClose
  src
    package DBCommon
    DBConfig.properties

(couldn't paste a pic due insufficient reputation)

Filename in the code is as follows:

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

ResourceBundle DBconfig = ResourceBundle.getBundle(FILENAME);

The exception I am getting is:

I don't understand why locale en_US is coming up as I am only using the basename when calling this method. Any help is appreciated. I have gone through similar related posts but they didn't help me.

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)

2

2 Answers

3
votes

Remove ".properties" from the FILENAME.

EDIT: Here are the specifics on 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.

0
votes

ResourceBundle.getBundle(String) wants a resource bundle (base) name, not a file name. It will construct one or more candidate file names from the bundle name if it cannot find an appropriate class implementing the bundle.

As for the locale, resource bundle lookups are always locale-specific. That's the whole point of them. The variant of the getBundle() method that you are using uses the system's default locale to perform the lookup, and for you that's "en_US". That does not mean, however, that the actual bundle loaded will be necessarily specific to that locale. If no locale-specific bundle is found, and a base bundle is available, then the base bundle will be loaded. (The same applies when you specify a locale explicitly.)