Android为textView设置setText的时候报错的讲解方案
在对中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()+""); } }
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对的支持。如果你想了解更多相关内容请查看下面相关链接