TextView在android模拟器上导致错误

时间:2014-03-20 16:42:49

标签: android

我创建TextView并将其设置为显示某个变量的值。当我运行android模拟器时,问题就出现了,应用程序正常启动,但是当我点击屏幕让TextView在屏幕上显示时,它就出现了错误。

这是此应用程序的LogCat。

03-20 11:38:02.871: D/dalvikvm(3662): GC_FOR_ALLOC freed 86K, 5% free 3047K/3200K, paused 55ms, total 57ms
03-20 11:38:02.901: I/dalvikvm-heap(3662): Grow heap (frag case) to 4.930MB for 1987216-byte allocation
03-20 11:38:02.951: D/dalvikvm(3662): GC_FOR_ALLOC freed 2K, 4% free 4985K/5144K, paused 42ms, total 42ms
03-20 11:38:03.981: I/Choreographer(3662): Skipped 30 frames!  The application may be doing too much work on its main thread.
03-20 11:38:04.031: D/gralloc_goldfish(3662): Emulator without GPU emulation detected.
03-20 11:38:16.111: I/Choreographer(3662): Skipped 345 frames!  The application may be doing too much work on its main thread.
03-20 11:38:22.541: W/ResourceType(3662): No package identifier when getting value for resource number 0x00000001
03-20 11:38:22.551: D/AndroidRuntime(3662): Shutting down VM
03-20 11:38:22.551: W/dalvikvm(3662): threadid=1: thread exiting with uncaught exception (group=0xb1af5ba8)
03-20 11:38:22.601: E/AndroidRuntime(3662): FATAL EXCEPTION: main
03-20 11:38:22.601: E/AndroidRuntime(3662): Process: com.example.yyy, PID: 3662
03-20 11:38:22.601: E/AndroidRuntime(3662): android.content.res.Resources$NotFoundException: String resource ID #0x1
03-20 11:38:22.601: E/AndroidRuntime(3662):     at android.content.res.Resources.getText(Resources.java:244)
03-20 11:38:22.601: E/AndroidRuntime(3662):     at android.widget.TextView.setText(TextView.java:3888)
03-20 11:38:22.601: E/AndroidRuntime(3662):     at com.example.yyy.Find2Activity.onClick(Find2Activity.java:167)
03-20 11:38:22.601: E/AndroidRuntime(3662):     at android.view.View.performClick(View.java:4438)
03-20 11:38:22.601: E/AndroidRuntime(3662):     at android.view.View$PerformClick.run(View.java:18422)
03-20 11:38:22.601: E/AndroidRuntime(3662):     at android.os.Handler.handleCallback(Handler.java:733)
03-20 11:38:22.601: E/AndroidRuntime(3662):     at android.os.Handler.dispatchMessage(Handler.java:95)
03-20 11:38:22.601: E/AndroidRuntime(3662):     at android.os.Looper.loop(Looper.java:136)
03-20 11:38:22.601: E/AndroidRuntime(3662):     at android.app.ActivityThread.main(ActivityThread.java:5017)
03-20 11:38:22.601: E/AndroidRuntime(3662):     at java.lang.reflect.Method.invokeNative(Native Method)
03-20 11:38:22.601: E/AndroidRuntime(3662):     at java.lang.reflect.Method.invoke(Method.java:515)
03-20 11:38:22.601: E/AndroidRuntime(3662):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
03-20 11:38:22.601: E/AndroidRuntime(3662):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
03-20 11:38:22.601: E/AndroidRuntime(3662):     at dalvik.system.NativeStart.main(Native Method)
03-20 11:38:27.071: I/Process(3662): Sending signal. PID: 3662 SIG: 9

1 个答案:

答案 0 :(得分:4)

android.content.res.Resources$NotFoundException: String resource ID #0x1

堆栈跟踪通过yourTextView.setText(1);告诉您正在调用1 作为int值。将其更改为yourTextView.setText(""+1);以将该值转换为String。

如果你将一个int传递给setText android会尝试查找id你提供的int的字符串