By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,640 Members | 2,110 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,640 IT Pros & Developers. It's quick & easy.

<Can't find bundle for base name> is driving me mad

P: n/a
Hi all,

Although i'm not a complete newbie i do feel like one at the moment.

This question concerns the use of the ResourceBundle as per the example in
the Trail tutorial on java.sun.com (thus it should be simple, right?).

The error:
java.util.MissingResourceException: Can't find bundle for base name
LabelsBundle, locale en_US
at java.util.ResourceBundle.throwMissingResourceExcep tion(Unknown Source)
at java.util.ResourceBundle.getBundleImpl(Unknown Source)
at java.util.ResourceBundle.getBundle(Unknown Source)
at multilanguage.PropertiesDemo.displayValue(Properti esDemo.java:25)
at multilanguage.PropertiesDemo.main(PropertiesDemo.j ava:46)

Attached is the code and the three prop files i (try to) use.

I know about the classpath suggestions that can be found all over the place
but the prop files are just sitting nicely in the same dir where the
PropertiesDemo.class file resides (and is started from). This suggests to
me that the classpath is ok (right?).

Should not matter but i'm using Eclipse 3M7.

If anybody could help me out here i would really appreciate it. It is
already bugging me for more than 4 hours now :-[[

TIA
Fermin DCG

package multilanguage;

/*
* Copyright (c) 1995-1998 Sun Microsystems, Inc. All Rights Reserved.
*
* Permission to use, copy, modify, and distribute this software
* and its documentation for NON-COMMERCIAL purposes and without
* fee is hereby granted provided that this copyright notice
* appears in all copies. Please refer to the file "copyright.html"
* for further important copyright and licensing information.
*
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
* THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
* TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
*/

import java.util.*;

public class PropertiesDemo {

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.setDefault(new Locale("en_US"));
Locale[] supportedLocales = {Locale.FRENCH, Locale.GERMAN, Locale.ENGLISH};

for (int i = 0; i < supportedLocales.length; i++) {
displayValue(supportedLocales[i], "s2");
}

System.out.println();
iterateKeys(supportedLocales[0]);
} // main

} // class

#s1 comment
s1=computer

#Comment s2
s2=Platte

#Comment s3
s3=Monitor

#Comment keyboard
s4=Tastatur
#s1 comment
s1=computer

#Comment s2
s2=disk

#Comment s3
s3=monitor

#Comment keyboard
s4=keyboard
#s1 comment
s1=fr_computer

#Comment s2
s2=fr_disk

#Comment s3
s3=fr_monitor

#Comment keyboard
s4=fr_keyboard
#s1 comment
s1=computer

#Comment s2
s2=disk

#Comment s3
s3=monitor

#Comment keyboard
s4=keyboard
Jul 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.