在我的应用程序中,我正在进行语言本地化。它与按钮和texviews完美配合,但无法更改recyclerview上的字符串
它说 NumberFormatException:无效的int:""
private void updateViews(String languageCode) {
Context context = LocaleHelper.setLocale(MainActivity.this, languageCode);
Resources resources = context.getResources();
changelang.setText(resources.getString(R.string.changelanguage));
languagename.setText(resources.getString(R.string.languagename));
//error with following line object01.setDepname(Integer.parseInt(resources.getString(R.string.cultivation)));
}
});

堆栈跟踪
java.lang.NumberFormatException: Invalid int: "खेती"
at java.lang.Integer.invalidInt(Integer.java:138)
at java.lang.Integer.parse(Integer.java:410)
at java.lang.Integer.parseInt(Integer.java:367)
at java.lang.Integer.parseInt(Integer.java:334)
at com.example.rimapps.icar_iisr_ginger.MainActivity$1.updateViews(MainActivity.java:125)
at com.example.rimapps.icar_iisr_ginger.MainActivity$1.access$000(MainActivity.java:92)
at com.example.rimapps.icar_iisr_ginger.MainActivity$1$1.onClick(MainActivity.java:101)
at android.support.v7.app.AlertController$AlertParams$3.onItemClick(AlertController.java:1044)
at android.widget.AdapterView.performItemClick(AdapterView.java:310)
at android.widget.AbsListView.performItemClick(AbsListView.java:1145)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3081)
at android.widget.AbsListView$3.run(AbsListView.java:3947)
at android.os.Handler.handleCallback(Handler.java:742)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:5523)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)

请帮助
答案 0 :(得分:5)
您正在尝试将资源中的字符串转换为整数值。这是不可能的! 要支持多种语言,请使用所需的语言环境创建一个新的string.xml。
请参阅https://developer.android.com/training/basics/supporting-devices/languages.html
答案 1 :(得分:0)
当您尝试将资源中的字符串转换为整数值时。这是不可能的,所以尝试以这种方式改变模型类
public class ContentsDep {
int depimage;
String depname;
public int getDepimage() {return depimage;
}
public void setDepimage(int depimage) {this.depimage = depimage;
}
public void setDepname(String depname) {
this.depname = depname;
}
public String getDepname() {return depname;}
}
然后像这样设置值
object01.setDepname(resources.getString(R.string.cultivation));