0

我正在使用 android,并且对它比较陌生,我遇到了一个我似乎无法修复的异常。

日志输出

10-24 13:50:59.941: E/AndroidRuntime(772): FATAL EXCEPTION: main
10-24 13:50:59.941: E/AndroidRuntime(772): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.metronome/com.metronome.MainActivity}: android.content.res.Resources$NotFoundException: String resource ID #0x78
10-24 13:50:59.941: E/AndroidRuntime(772):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
10-24 13:50:59.941: E/AndroidRuntime(772):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
10-24 13:50:59.941: E/AndroidRuntime(772):  at android.app.ActivityThread.access$600(ActivityThread.java:122)
10-24 13:50:59.941: E/AndroidRuntime(772):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
10-24 13:50:59.941: E/AndroidRuntime(772):  at android.os.Handler.dispatchMessage(Handler.java:99)
10-24 13:50:59.941: E/AndroidRuntime(772):  at android.os.Looper.loop(Looper.java:137)
10-24 13:50:59.941: E/AndroidRuntime(772):  at android.app.ActivityThread.main(ActivityThread.java:4340)
10-24 13:50:59.941: E/AndroidRuntime(772):  at java.lang.reflect.Method.invokeNative(Native Method)
10-24 13:50:59.941: E/AndroidRuntime(772):  at java.lang.reflect.Method.invoke(Method.java:511)
10-24 13:50:59.941: E/AndroidRuntime(772):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-24 13:50:59.941: E/AndroidRuntime(772):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-24 13:50:59.941: E/AndroidRuntime(772):  at dalvik.system.NativeStart.main(Native Method)
10-24 13:50:59.941: E/AndroidRuntime(772): Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x78
10-24 13:50:59.941: E/AndroidRuntime(772):  at android.content.res.Resources.getText(Resources.java:247)
10-24 13:50:59.941: E/AndroidRuntime(772):  at android.widget.TextView.setText(TextView.java:3432)
10-24 13:50:59.941: E/AndroidRuntime(772):  at com.metronome.MainActivity.onCreate(MainActivity.java:36)
10-24 13:50:59.941: E/AndroidRuntime(772):  at android.app.Activity.performCreate(Activity.java:4465)
10-24 13:50:59.941: E/AndroidRuntime(772):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
10-24 13:50:59.941: E/AndroidRuntime(772):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
10-24 13:50:59.941: E/AndroidRuntime(772):  ... 11 more

我读过人们说要通过清理项目来解决问题,但我已经尝试了两次,但没有帮助。我还创建了另一个项目并复制了代码,所以我认为这是不同的东西。任何帮助表示赞赏。

第 36 行

txtBPM1.setText(120, TextView.BufferType.EDITABLE);
4

3 回答 3

1

onCreate当您访问某些控件或您在活动中传递的布局中不存在的控件时,会发生此错误setContentView(R.layout.your_layout);。只需检查您使用的所有 id 、 string 和其他控件是否属于相同布局

于 2012-10-24T14:16:16.097 回答
0

(您在 MainActivity.java 中的错误:第 36 行(它是导入生成的 R)) 1. 从导入中删除错误行并在红色 R.id 上使用弹出消息。* * 2.关闭并重新打开IDE

于 2012-10-24T14:14:39.497 回答
0

将 120 更改为这样的字符串:

txtBPM1.setText(""+120, TextView.BufferType.EDITABLE);
于 2012-10-24T14:15:04.523 回答