由于某种原因,我无法弄清楚,当我将代码放入标签内单击按钮时,应用程序强制停止。这是代码:
Button btn = (Button)tabs.getCurrentView().findViewById(R.id.button1);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
知道出了什么问题吗?
这是logcat
02-20 22:31:22.328: E/AndroidRuntime(7074): FATAL EXCEPTION: main
02-20 22:31:22.328: E/AndroidRuntime(7074): java.lang.RuntimeException: Unable to start activity ComponentInfo{particularidiom.doodledot/com.yabt.Chooser}: java.lang.NullPointerException
02-20 22:31:22.328: E/AndroidRuntime(7074): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
02-20 22:31:22.328: E/AndroidRuntime(7074): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
02-20 22:31:22.328: E/AndroidRuntime(7074): at android.app.ActivityThread.access$600(ActivityThread.java:123)
02-20 22:31:22.328: E/AndroidRuntime(7074): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
02-20 22:31:22.328: E/AndroidRuntime(7074): at android.os.Handler.dispatchMessage(Handler.java:99)
02-20 22:31:22.328: E/AndroidRuntime(7074): at android.os.Looper.loop(Looper.java:137)
02-20 22:31:22.328: E/AndroidRuntime(7074): at android.app.ActivityThread.main(ActivityThread.java:4424)
02-20 22:31:22.328: E/AndroidRuntime(7074): at java.lang.reflect.Method.invokeNative(Native Method)
02-20 22:31:22.328: E/AndroidRuntime(7074): at java.lang.reflect.Method.invoke(Method.java:511)
02-20 22:31:22.328: E/AndroidRuntime(7074): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
02-20 22:31:22.328: E/AndroidRuntime(7074): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
02-20 22:31:22.328: E/AndroidRuntime(7074): at dalvik.system.NativeStart.main(Native Method)
02-20 22:31:22.328: E/AndroidRuntime(7074): Caused by: java.lang.NullPointerException
02-20 22:31:22.328: E/AndroidRuntime(7074): at com.yabt.Chooser.onCreate(Chooser.java:134)
02-20 22:31:22.328: E/AndroidRuntime(7074): at android.app.Activity.performCreate(Activity.java:4465)
02-20 22:31:22.328: E/AndroidRuntime(7074): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
02-20 22:31:22.328: E/AndroidRuntime(7074): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
02-20 22:31:22.328: E/AndroidRuntime(7074): ... 11 more
答案 0 :(得分:0)
我想你的代码中的按钮btn
为空。可能是您在上面的代码示例中没有得到准确的R.id
。
答案 1 :(得分:0)