Localization +Problem Instantiating


I’m really blocked in a problem, i’m trying to use localization and internationalization in my vaadin application.
this the code that causes problem.
lc = new ArrayList();
cbLanguage = new ComboBox(null, lc);
cbLanguage.addListener(new Property.ValueChangeListener() {

        private static final long serialVersionUID = 1L;

        public void valueChange(ValueChangeEvent event) {
            language = event.getProperty().toString();
            if (language.equals("FR")) {
                captions = ResourceBundle.getBundle("Labels", new Locale("fr", "FR"));
            } else if (language.equals("EN")) {
                captions = ResourceBundle.getBundle("Labels", new Locale("en", "US"));

In fact, the getWindow.showNotification show me that the “captions” object is really instiantiated. (i use it just for testing if the captions object is really instantiated)
But when i try to use it later i got NullPointerException.

speciflabel = new Label(captions.getString(“lbSpecification”));

Can anyone help me!!


Do you initialize the “captions” member somewhere? If you initialize it only in the ValueChangeListener, it will be null until the user selects an item and the listener is called.

You don’t need the if-conditionals in language selection. You should put language IDs like “fr_FR” and “en_US” in the combobox as item IDs, and set the item captions of those items to “French” and “English”, respectively. Then, in the ValueChangeListener, use the language ID directly in new Locale(itemId).

Also, you shouldn’t use strings as resource IDs, as it’s really easy to typo them and then you’ll get a MissingResourceException.

Language selection is demonstrated in
(and the application class) in the Gas Diary example. You can run the demo
here on-line
to see how it works.

There’s also this new
add-on, which helps with internationalization. It can switch the language without having to reconstruct the UI.


Thanks Marko Gronroos for your help. it works well with the vaadin add-on!!!