我在View中添加了Group Radio(android.view.View)
RadioGroup radioGroup = (RadioGroup) findViewById(R.id.radioGroup1);
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()
{
public void onCheckedChanged(RadioGroup group, int checkedId) {
//---displays the ID of the RadioButton that is checked---
System.out.printf(String.format("\n Id : %d", checkedId));
}
});
但是语法错误,它显示:
02-07 21:10:09.918: E/AndroidRuntime(230): Uncaught handler: thread main exiting due to uncaught exception
02-07 21:10:09.928: E/AndroidRuntime(230): java.lang.NullPointerException
02-07 21:10:09.928: E/AndroidRuntime(230): at com.v2nhat.myPikachu.View.QuickPlayView.selectLevel(QuickPlayView.java:28)
02-07 21:10:09.928: E/AndroidRuntime(230): at com.v2nhat.myPikachu.View.QuickPlayView.onTouchEvent(QuickPlayView.java:51)
02-07 21:10:09.928: E/AndroidRuntime(230): at android.view.View.dispatchTouchEvent(View.java:3709)
02-07 21:10:09.928: E/AndroidRuntime(230): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:822)
02-07 21:10:09.928: E/AndroidRuntime(230): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:822)
02-07 21:10:09.928: E/AndroidRuntime(230): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:822)
02-07 21:10:09.928: E/AndroidRuntime(230): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
02-07 21:10:09.928: E/AndroidRuntime(230): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
02-07 21:10:09.928: E/AndroidRuntime(230): at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
02-07 21:10:09.928: E/AndroidRuntime(230): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
02-07 21:10:09.928: E/AndroidRuntime(230): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
02-07 21:10:09.928: E/AndroidRuntime(230): at android.os.Handler.dispatchMessage(Handler.java:99)
02-07 21:10:09.928: E/AndroidRuntime(230): at android.os.Looper.loop(Looper.java:123)
02-07 21:10:09.928: E/AndroidRuntime(230): at android.app.ActivityThread.main(ActivityThread.java:4363)
02-07 21:10:09.928: E/AndroidRuntime(230): at java.lang.reflect.Method.invokeNative(Native Method)
02-07 21:10:09.928: E/AndroidRuntime(230): at java.lang.reflect.Method.invoke(Method.java:521)
02-07 21:10:09.928: E/AndroidRuntime(230): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
02-07 21:10:09.928: E/AndroidRuntime(230): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
02-07 21:10:09.928: E/AndroidRuntime(230): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:0)
因为您很可能导入(或您的IDE确实)错误的类(例如CheckBox
也有OnCheckedChangeListener()
)。试试
radioGroup.setOnCheckedChangeListener(new Radio.OnCheckedChangeListener()
或删除/修复错误的导入。