在对中TextView setText 覆值int 时报错,网上查下原因是setText整型表明是设值R.id.xxx,当然找不到。
解决方法是将int转化为string,用String.valueOf(xxx)
一、我的代码如下:就是我textView设置值
if (list != null) { for (Student stu : list) { //如果一下子赋值的话是不正确的 tv_name.setText(stu.getName()); tv_sex.setText(stu.getSex()); tv_age.setText(stu.getAge()); } }
报出错误:
04-04 08:56:33.950: W/ResourceType(23332): No package identifier when getting value for resource number 0x0000000c
04-04 08:56:33.950: D/AndroidRuntime(23332): Shutting down VM
04-04 08:56:33.950: W/dalvikvm(23332): threadid=1: thread exiting with uncaught exception (group=0x416ddd58)
04-04 08:56:33.960: E/AndroidRuntime(23332): FATAL EXCEPTION: main
04-04 08:56:33.960: E/AndroidRuntime(23332): Process: com.xuliugen.studentsytem, PID: 23332
04-04 08:56:33.960: E/AndroidRuntime(23332): android.content.res.Resources$NotFoundException: String resource ID #0xc
android.content.res.Resources.getText(Resources.java:252)
04-04 08:56:33.960: E/AndroidRuntime(23332): at android.content.res.MiuiResources.getText(MiuiResources.java:107)
04-04 08:56:33.960: E/AndroidRuntime(23332): at android.widget.TextView.setText(TextView.java:3895)
04-04 08:56:33.960: E/AndroidRuntime(23332): at com.xuliugen.ui.activity.StudentManagerActivity$1.onClick(StudentManagerActivity.java:82)
04-04 08:56:33.960: E/AndroidRuntime(23332): at android.view.View.performClick(View.java:4444)
04-04 08:56:33.960: E/AndroidRuntime(23332): at android.view.View$PerformClick.run(View.java:18457)
04-04 08:56:33.960: E/AndroidRuntime(23332): at android.os.Handler.handleCallback(Handler.java:733)
04-04 08:56:33.960: E/AndroidRuntime(23332): at android.os.Handler.dispatchMessage(Handler.java:95)
04-04 08:56:33.960: E/AndroidRuntime(23332): at android.os.Looper.loop(Looper.java:136)
04-04 08:56:33.960: E/AndroidRuntime(23332): at android.app.ActivityThread.main(ActivityThread.java:5034)
04-04 08:56:33.960: E/AndroidRuntime(23332): at java.lang.reflect.Method.invokeNative(Native Method)
04-04 08:56:33.960: E/AndroidRuntime(23332): at java.lang.reflect.Method.invoke(Method.java:515)
04-04 08:56:33.960: E/AndroidRuntime(23332): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:807)
04-04 08:56:33.960: E/AndroidRuntime(23332): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:623)
04-04 08:56:33.960: E/AndroidRuntime(23332): at dalvik.system.NativeStart.main(Native Method)
具体解决方法:
if (list != null) { for (Student stu : list) { //如果一下子赋值的话是不正确的 tv_name.setText(stu.getName()+""); tv_sex.setText(stu.getSex()+""); tv_age.setText(stu.getAge()+""); } }
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对自由互联的支持。如果你想了解更多相关内容请查看下面相关链接