Android为textView设置setText的时候报错

时间:2021-09-07 17:06:16

一、我的代码如下:就是我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)

Android为textView设置setText的时候报错

具体解决方法:

if (list != null) {
for (Student stu : list) {
//如果一下子赋值的话是不正确的
tv_name.setText(stu.getName()+"");
tv_sex.setText(stu.getSex()+"");
tv_age.setText(stu.getAge()+"");
}
}