我目前在Java教程Oracle上学习国际化。当我尝试运行下面的代码时,IDE始终显示错误消息:
Exception in thread "main" java.util.MissingResourceException: Can't find bundle for base name Internationalisation/StatsBundle, locale en_US
at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1564)
at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1387)
at java.util.ResourceBundle.getBundle(ResourceBundle.java:845)
at Internationalisation.ListDemo.displayValues(ListDemo.java:20)
at Internationalisation.ListDemo.main(ListDemo.java:41)
Java Result: 1
这是我的代码:
public class ListDemo {
static void displayValues(Locale currentLocale) {
ResourceBundle stats =
ResourceBundle.getBundle("Internationalisation/StatsBundle",currentLocale);
Integer gdp = (Integer)stats.getObject("GDP");
System.out.println("GDP = " + gdp.toString());
Integer pop = (Integer)stats.getObject("Population");
System.out.println("Population = " + pop.toString());
Double lit = (Double)stats.getObject("Literacy");
System.out.println("Literacy = " + lit.toString());
} // displayValues
static public void main(String[] args) {
Locale[] supportedLocales = {
new Locale("en", "US"),
new Locale("ja","JP"),
new Locale("fr","FR")
};
for (int i = 0; i < supportedLocales.length; i ++) {
System.out.println("Locale = " + supportedLocales[i]);
displayValues(supportedLocales[i]);
System.out.println();
}
} // main
} // class