Exception in thread "main" java.util.MissingResourceException: Can't find

Hi,

This is my code, I could not find the solution of my problem,

--

package propertiesdemo;

import java.util.*;

public class Main {

static void displayValue(Locale currentLocale, String key) {

ResourceBundle labels =

ResourceBundle.getBundle("LabelsBundle",currentLocale);

String value = labels.getString(key);

System.out.println(

"Locale = " + currentLocale.toString() + ", " +

"key = " + key + ", " +

"value = " + value);

} // displayValue

static void iterateKeys(Locale currentLocale) {

ResourceBundle labels =

ResourceBundle.getBundle("LabelsBundle",currentLocale);

Enumeration bundleKeys = labels.getKeys();

while (bundleKeys.hasMoreElements()) {

String key = (String)bundleKeys.nextElement();

String value = labels.getString(key);

System.out.println("key = " + key + ", " +

"value = " + value);

}

} // iterateKeys

public static void main(String[] args) {

Locale[] supportedLocales = {

Locale.FRENCH,

Locale.GERMAN,

Locale.ENGLISH

};

for (int i = 0; i < supportedLocales.length; i ++) {

displayValue(supportedLocales, "s2");

}

System.out.println();

iterateKeys(supportedLocales[0]);

} // main

} // class

--

# This is the default LabelsBundle.properties file

# Key is on the Left Hand Side of the (=) sign.

# Value is on the Right Hand Side of the (=) sign.

s1 = computer

s2 = disk

s3 = monitor

s4 = keyboard

--

# This is the LabelsBundle_de.properties file

# Key is on the Left Hand Side of the (=) sign.

# Value is on the Right Hand Side of the (=) sign.

s1 = Computer

s2 = Platte

s3 = Monitor

s4 = Tastatur

--

# This is the LabelsBundle_fr.properties file

# Key is on the Left Hand Side of the (=) sign.

# Value is on the Right Hand Side of the (=) sign.

s1 = Computer

s2 = Platte

s3 = Monitor

s4 = Tastatur

--

I got the following Exceptions.

init:

deps-jar:

Compiling 1 source file to C:\Documents and Settings\user1\propertiesDemo\build\classes

compile:

run:Exception in thread "main" java.util.MissingResourceException: Can't find bundle for base name LabelsBundle, locale fr

at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:836)

at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:805)

at java.util.ResourceBundle.getBundle(ResourceBundle.java:576)

at propertiesdemo.Main.displayValue(Main.java:20)

at propertiesdemo.Main.main(Main.java:55)

Java Result: 1

BUILD SUCCESSFUL (total time: 0 seconds)

-

How to solve this?

thanks

[2878 byte] By [discuss_javaa] at [2007-11-27 11:53:32]
# 1

I tried your code and it worked fine.

Locale = fr, key = s2, value = Platte

Locale = de, key = s2, value = Platte

Locale = en, key = s2, value = disk

key = s2, value = Platte

key = s1, value = Computer

key = s3, value = Monitor

key = s4, value = Tastatur

I suspect that you put the properties files in a wrong directory. They should be under classes/, like this:

classes/LabelsBundle.properties

classes/LabelsBundle_de.properties

classes/LabelsBundle_fr.properties

classes/propertiesdemo/Main.class

Masayoshi

okutsua at 2007-7-29 18:50:49 > top of Java-index,Desktop,I18N...
# 2

Thanks

but i am using NetBeans IDE 5.5.

I don't know how to and where to put these files. My all files whether it is .java file or .properties files are in the same directory.

still i am trying ... if know please reply me.

Thanks for help.

regards

discuss_javaa at 2007-7-29 18:50:49 > top of Java-index,Desktop,I18N...