Java:missingresourceexception, "Can ' t find bundle for base name Mymessage, Locale ZH_CN"

Source: Internet
Author: User
Tags i18n locale

In Java, you can use the *.java class as a resource file for multi-language internationalization.

1. First define the class, the class must inherit ListResourceBundle

The path to the class is: src/i18n

1  Public classMymessage_en_usextendsListResourceBundle {2 3     Private FinalObject mydata[][] = {{"Hello", "hello! " },4{"Greetting", "Love you." {0} " } };5 6 @Override7     protectedobject[][] getcontents () {8         returnMyData;9     }Ten  One}

2. Writing test cases, using resource files

This file is in the default package

    Static void Main () {        new Locale ("zh", "CN");         = Resourcebundle.getbundle ("Mymessage", current);         = Bundle.getstring ("greetting");        " Jay "));    

Unfortunately, it's a mistake.

Exception in thread "main" Java.util.MissingResourceException:Can ' t find bundle for base name Mymessage, Locale ZH_CN  At    java.util.ResourceBundle.throwMissingResourceException (Unknown Source)    at Java.util.ResourceBundle.getBundleImpl (Unknown source) at    Java.util.ResourceBundle.getBundle (Unknown source) At program    . I18ntest (Program.java:) at    program.main (Program.java:20)

After many attempts, the main functions of class Mymessage_en_us and invocation are placed under the default package. That's it.

Output results

Hello, Jay.

Seems to be a resource path problem, after a variety of attempts to modify the path, as follows

Private Static void i18ntest () {        new Locale ("zh", "CN");          = Resourcebundle.getbundle ("i18n.mymessage", current);         = Bundle.getstring ("greetting");        " Jay "));    

Instead of modifying the path where the file is stored.

Java:missingresourceexception, "Can ' t find bundle for base name Mymessage, Locale ZH_CN"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.