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

