Forum Stats

  • 3,853,777 Users
  • 2,264,267 Discussions
  • 7,905,444 Comments

Discussions

Language Resource file not found: Can't find resource for bundle java.util.PropertyResourceBundle

I am trying to get past a hurdle with my application. Seems that my code is have a problem finding the resource bundle. Error reads Language Resource file not found: java.util.MissingResourceException: Can't find resource for bundle java.util.PropertyResourceBundle, key Login. yes I am using "resource/login" but the resource files are login.properties, login_en_us.properties, etc. is there anything to reference to get better information for intelliJ 2022.2.1? I am having a hard time finding anything. I am trying to figure out What java is looking for or how it trying to locate the properties file.

Thank you for the help.


Error: Language Resource file not found: Can't find resource for bundle java.util.PropertyResourceBundle, key Login


Line of code in question rb = ResourceBundle.getBundle("Language/Login", Locale.getDefault());



Tagged:

Answers

  • Ana Kalemi
    Ana Kalemi Member Posts: 8 Green Ribbon
    edited Sep 20, 2022 6:59PM

    To initialize the ResourceBoundle object:

    ResourceBundle rb = ResourceBundle.getBundle("package.BundleName", locale);

    where the package refers to the package where the properties file is located, otherwise if located in the same package as the java file trying to read it, it can be omitted. (In your case I am guessing it is resource)

    And the BundleName here refers to the name of the properties file, in your case login.

    From your description only (attached image cannot be found), I would recommend trying:

    ResourceBundle rb = ResourceBundle.getBundle("resource.login", Locale.getDefault());


    Please also note:

    To determine which bundle belongs to a particular locale, Java tries to find the most specific bundle that matches the properties of the locale. This means that:

    1. Java first searches for a bundle whose name matches the complete locale:

    package.bundle_language_country_variant

    2. If it cannot find one, it drops the last component of the name and repeats the search:

    package.bundle_language_country

    3. If it cannot find one, again, it drops the last component of the name and repeats the search:

    package.bundle_language

    4. If still cannot find one, the last component is dropped again, leaving just the name of the bundle:

    package.bundle

    If nothing is found, a MissingBundleException is thrown. If a class and a property file share the same name, Java gives priority to the class.

    Good Luck @User_X22A3