java国际化程序时出现了这样的错误:
Exceptioninthread"main"java.util.MissingResourceException:Can'tfindbundleforbasenameM...
Exception in thread "main" java.util.MissingResourceException: Can't find bundle for base name Message, locale zh_CN
//代码:
package InternationalProgram;
import java.text.MessageFormat;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.Scanner;
public class InternationalProgram {
public static void main(String[] args){
Locale zhLoc=new Locale("zh","CN");
Locale enLoc=new Locale("en","US");
ResourceBundle zhrb=ResourceBundle.getBundle("Message", zhLoc);
ResourceBundle enrb=ResourceBundle.getBundle("Message", enLoc);
boolean isContinue=true;
while(isContinue){
System.out.println("请选择语言:");
System.out.println("1)中文\t2)英文\t0)退出");
Scanner sc=new Scanner(System.in);
String input=sc.next();
switch(input){
case "1":
String s1=zhrb.getString("info");
System.out.println(MessageFormat.format(s1, "李力"));
break;
case "2":
String s2=enrb.getString("info");
System.out.println(MessageFormat.format(s2, "black"));
break;
case "0":
isContinue=false;
break;
default:
System.out.println("无此功能选择,请重新选择!");
break;
}
}
}
}
//Message_zh_CN.properties
info=\u4f60\u597d\uff0c{0}\uff01
//Message_en_US.properties
info=Hello,{0}! 展开
//代码:
package InternationalProgram;
import java.text.MessageFormat;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.Scanner;
public class InternationalProgram {
public static void main(String[] args){
Locale zhLoc=new Locale("zh","CN");
Locale enLoc=new Locale("en","US");
ResourceBundle zhrb=ResourceBundle.getBundle("Message", zhLoc);
ResourceBundle enrb=ResourceBundle.getBundle("Message", enLoc);
boolean isContinue=true;
while(isContinue){
System.out.println("请选择语言:");
System.out.println("1)中文\t2)英文\t0)退出");
Scanner sc=new Scanner(System.in);
String input=sc.next();
switch(input){
case "1":
String s1=zhrb.getString("info");
System.out.println(MessageFormat.format(s1, "李力"));
break;
case "2":
String s2=enrb.getString("info");
System.out.println(MessageFormat.format(s2, "black"));
break;
case "0":
isContinue=false;
break;
default:
System.out.println("无此功能选择,请重新选择!");
break;
}
}
}
}
//Message_zh_CN.properties
info=\u4f60\u597d\uff0c{0}\uff01
//Message_en_US.properties
info=Hello,{0}! 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询