For Programmers: Free Programming Magazines  


Home > Archive > Java Help > March 2004 > Re: <Can't find bundle for base name> (solved)









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: <Can't find bundle for base name> (solved)
F. Da Costa

2004-03-31, 6:46 pm

F. Da Costa Gomez wrote:

> 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.throwMissingResourceException(Unknown
> Source)
> at java.util.ResourceBundle.getBundleImpl(Unknown Source)
> at java.util.ResourceBundle.getBundle(Unknown Source)
> at multilanguage.PropertiesDemo.displayValue(PropertiesDemo.java:25)
> at multilanguage.PropertiesDemo.main(PropertiesDemo.java: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.
>

For some mysterious reason the files should be at the very beginning of the
classpath. Why? Who knows!!

> 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
>
>

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com