Question about resource not found in resourcebundle

Source: Internet
Author: User

 

 

1)Directory structure:

| Build. xml
+ --- Build
|/--- Classes
|/--- Com
|/--- Nana
|/--- Test
| Scrap. Class
|
+ --- SRC
|/--- Com
|/--- Nana
|/--- Test
| Autogen. Properties
| Scrap. Java

 

2)Problem description:

Resourcebundle RB = resourcebundle.Getbundle("Autogen. properties", locale.Getdefault());

 

Exception in thread "Main" Java. util. missingresourceexception: Can't Find bundle for base name autogen. properties, 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 com. Nana. Test. autogen. Main (autogen. Java: 25)

 

3)Solution:

1. These resource properties files are loaded by classloader, which is similar to java files. Therefore, you should add these files to classpath.

2. resourcebundle. getbundle ("com. Nana. Test. autogen") tells the classloader to load a resource named "autogen" and the package named "com. Nana. test ".

3. if you do not want to write the package name, you can directly obtain autogen. properties, you need to set autogen. copy the properties file to the classes/COM/Nana/test/directory, together with the class file that calls it.

Resourcebundle RB = resourcebundle.Getbundle("Autogen", locale.Getdefault());

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.