我即将开发Android 2.2.3,Gingerbread。 APILevel 10申请。 我在EditText上调用一个侦听器来捕获 Enter 键按事件。 问题是,当我在我的应用程序中点击 Enter 时,它会意外停止。 下面是它的主要代码块。
//Declare the listener
answertext.setOnEditorActionListener(answerOnKeyDownListener);
//Invoke the event handler
private TextView.OnEditorActionListener answerOnKeyDownListener = new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
{
if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)
{
answerOnClickListener.onClick(v);
}
return false;
}
};
}
当我按 Enter
时,这就是logcat告诉我的内容12-30 09:01:52.252: D/AndroidRuntime(522): Shutting down VM
12-30 09:01:52.252: W/dalvikvm(522): threadid=1: thread exiting with uncaught exception (group=0x40015560)
12-30 09:01:52.272: E/AndroidRuntime(522): FATAL EXCEPTION: main
12-30 09:01:52.272: E/AndroidRuntime(522): java.lang.NullPointerException
12-30 09:01:52.272: E/AndroidRuntime(522): at mental.arithmetic.MentalArithmeticActivity$5.onEditorAction(MentalArithmeticActivity.java:231)
12-30 09:01:52.272: E/AndroidRuntime(522): at android.widget.TextView.onEditorAction(TextView.java:3163)
12-30 09:01:52.272: E/AndroidRuntime(522): at com.android.internal.widget.EditableInputConnection.performEditorAction(EditableInputConnection.java:83)
12-30 09:01:52.272: E/AndroidRuntime(522): at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:291)
12-30 09:01:52.272: E/AndroidRuntime(522): at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:75)
12-30 09:01:52.272: E/AndroidRuntime(522): at android.os.Handler.dispatchMessage(Handler.java:99)
12-30 09:01:52.272: E/AndroidRuntime(522): at android.os.Looper.loop(Looper.java:123)
12-30 09:01:52.272: E/AndroidRuntime(522): at android.app.ActivityThread.main(ActivityThread.java:3683)
12-30 09:01:52.272: E/AndroidRuntime(522): at java.lang.reflect.Method.invokeNative(Native Method)
12-30 09:01:52.272: E/AndroidRuntime(522): at java.lang.reflect.Method.invoke(Method.java:507)
12-30 09:01:52.272: E/AndroidRuntime(522): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-30 09:01:52.272: E/AndroidRuntime(522): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-30 09:01:52.272: E/AndroidRuntime(522): at dalvik.system.NativeStart.main(Native Method)
12-30 09:02:01.132: I/Process(522): Sending signal. PID: 522 SIG: 9