DIRTY DAVE
DIRTY DAVE

Reputation: 2731

Trying to load a .properties file into Resource bundle getting error "Can't find bundle for base name"

I'm trying to load a .properties file into my ResourceBundle

public class Main extends Application {

    @Override
    public void start(Stage stage) throws Exception{

        ResourceBundle bundle = ResourceBundle.getBundle("/sample/resources/language_en.properties");

        FXMLLoader loader = new FXMLLoader(getClass().getResource("/sample/layout/test_form.fxml"), bundle);
    }
}

But I'm getting the error:

Caused by: java.util.MissingResourceException: Can't find bundle for base name /sample/resources/language_en.properties, locale en_US

enter image description here

Can't figure out why. I've checked the path multiple times /sample/resources/language_en.properties for spelling mistakes. I've also tried rebuilding the project (Using IntelliJ).

Does anyone have an idea why?

Upvotes: 1

Views: 1186

Answers (2)

Miss Chanandler Bong
Miss Chanandler Bong

Reputation: 4258

The method ResourceBundle.getBundle() takes the base name of the resource bundle, a fully qualified class name (as specified by the class documentation). You can load your bundle like this:

// this will load the base bundle: sample/resources/language.properties
ResourceBundle bundle = ResourceBundle.getBundle("sample.resources.language");

To use the English ResourceBundle, you can specify a Locale:

// this will load sample/resources/language_en.properties
ResourceBundle bundle = ResourceBundle.getBundle("sample.resources.language", Locale.ENGLISH);

Please refer to this tutorial for more information: Customizing Resource Bundle Loading

Upvotes: 2

seenukarthi
seenukarthi

Reputation: 8624

When loading resource bundle don't have .properties in basename extensions. Also, remove the leading / for the basename.

Use ResourceBundle bundle = ResourceBundle.getBundle("sample/resources/language_en");

Upvotes: 1

Related Questions