在EditText Touch上使用DatePickerDialog调度输入事件的异常

时间:2014-04-20 13:25:31

标签: android datepickerdialog

我在DatePickerDialog中使用activity。现在,对于更新数据,我使用EditDataActivity,其中EditText包含Date。当我触及EditText时,我收到错误 Exception dispatching input event

请帮我解决这个问题。

DatePicker代码:

DatePickerDialog.OnDateSetListener StartDate = new DatePickerDialog.OnDateSetListener() {

        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear,
                int dayOfMonth) {
            // TODO Auto-generated method stub

            myCalendar.set(Calendar.YEAR, year);
            myCalendar.set(Calendar.MONTH, monthOfYear);
            myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);

            String myFormat = "dd-MM-yyyy";
            SimpleDateFormat sdf = new SimpleDateFormat(myFormat,
                    Locale.getDefault());

            ((EditText) etEIOStartDate)
                    .setText(sdf.format(myCalendar.getTime()));
        }
    };

EditText触摸事件代码:

etEIOStartDate.setOnTouchListener(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                // TODO Auto-generated method stub

                switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    new DatePickerDialog(getApplicationContext(), StartDate,
                            myCalendar.get(Calendar.YEAR), myCalendar
                                    .get(Calendar.MONTH), myCalendar
                                    .get(Calendar.DAY_OF_MONTH)).show();
                    break;
                case MotionEvent.ACTION_UP:
                    break;
                }
                return true;
            }
        });

此处,EditText包含onCreate()的数据。即 15-09-2014



Logcat:

04-20 18:56:05.421: E/InputEventReceiver(23397): Exception dispatching input event.
04-20 18:56:05.421: E/MessageQueue-JNI(23397): Exception in MessageQueue callback: handleReceiveCallback
04-20 18:56:05.431: E/MessageQueue-JNI(23397): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
04-20 18:56:05.431: E/MessageQueue-JNI(23397):  at android.view.ViewRootImpl.setView(ViewRootImpl.java:707)
04-20 18:56:05.431: E/MessageQueue-JNI(23397):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:453)
04-20 18:56:05.431: E/MessageQueue-JNI(23397):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:351)
04-20 18:56:05.431: E/MessageQueue-JNI(23397):  at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:171)
04-20 18:56:05.431: E/MessageQueue-JNI(23397):  at android.app.Dialog.show(Dialog.java:282)
04-20 18:56:05.431: E/MessageQueue-JNI(23397):  at com.band.seekersstop.EditInstantOpportunity$5.onTouch(EditInstantOpportunity.java:180)
04-20 18:56:05.431: E/MessageQueue-JNI(23397):  at android.view.View.dispatchTouchEvent(View.java:7193)
04-20 18:56:05.431: E/MessageQueue-JNI(23397):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2187)
04-20 18:56:05.431: E/MessageQueue-JNI(23397):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1888)
04-20 18:56:05.431: E/MessageQueue-JNI(23397):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2187)
04-20 18:56:05.431: E/MessageQueue-JNI(23397):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1888)
04-20 18:56:05.431: E/MessageQueue-JNI(23397):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2187)
04-20 18:56:05.431: E/MessageQueue-JNI(23397):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1888)
04-20 18:56:05.431: E/MessageQueue-JNI(23397):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2187)
04-20 18:56:05.431: E/MessageQueue-JNI(23397):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1888)
04-20 18:56:05.431: E/MessageQueue-JNI(23397):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2187)
04-20 18:56:05.431: E/MessageQueue-JNI(23397):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1888)
04-20 18:56:05.431: E/MessageQueue-JNI(23397):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2187)
04-20 18:56:05.431: E/MessageQueue-JNI(23397):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1888)
04-20 18:56:05.431: E/MessageQueue-JNI(23397):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2187)
04-20 18:56:05.431: E/MessageQueue-JNI(23397):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1888)
04-20 18:56:05.431: E/MessageQueue-JNI(23397):  at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2052)
04-20 18:56:05.431: E/MessageQueue-JNI(23397):  at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1506)
04-20 18:56:05.431: E/MessageQueue-JNI(23397):  at android.app.Activity.dispatchTouchEvent(Activity.java:2454)
04-20 18:56:05.431: E/MessageQueue-JNI(23397):  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2000)
04-20 18:56:05.431: E/MessageQueue-JNI(23397):  at android.view.View.dispatchPointerEvent(View.java:7392)
04-20 18:56:05.431: E/MessageQueue-JNI(23397):  at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3539)
04-20 18:56:05.431: E/MessageQueue-JNI(23397):  at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3468)
04-20 18:56:05.431: E/MessageQueue-JNI(23397):  at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4577)
04-20 18:56:05.431: E/MessageQueue-JNI(23397):  at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4556)
04-20 18:56:05.431: E/MessageQueue-JNI(23397):  at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4652)
04-20 18:56:05.431: E/MessageQueue-JNI(23397):  at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:184)
04-20 18:56:05.431: E/MessageQueue-JNI(23397):  at android.os.MessageQueue.nativePollOnce(Native Method)
04-20 18:56:05.431: E/MessageQueue-JNI(23397):  at android.os.MessageQueue.next(MessageQueue.java:131)
04-20 18:56:05.431: E/MessageQueue-JNI(23397):  at android.os.Looper.loop(Looper.java:132)
04-20 18:56:05.431: E/MessageQueue-JNI(23397):  at android.app.ActivityThread.main(ActivityThread.java:5511)
04-20 18:56:05.431: E/MessageQueue-JNI(23397):  at java.lang.reflect.Method.invokeNative(Native Method)
04-20 18:56:05.431: E/MessageQueue-JNI(23397):  at java.lang.reflect.Method.invoke(Method.java:511)
04-20 18:56:05.431: E/MessageQueue-JNI(23397):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1029)
04-20 18:56:05.431: E/MessageQueue-JNI(23397):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:796)
04-20 18:56:05.431: E/MessageQueue-JNI(23397):  at dalvik.system.NativeStart.main(Native Method)
04-20 18:56:05.431: W/dalvikvm(23397): threadid=1: thread exiting with uncaught exception (group=0x415f2390)
04-20 18:56:05.441: E/AndroidRuntime(23397): FATAL EXCEPTION: main
04-20 18:56:05.441: E/AndroidRuntime(23397): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
04-20 18:56:05.441: E/AndroidRuntime(23397):    at android.view.ViewRootImpl.setView(ViewRootImpl.java:707)
04-20 18:56:05.441: E/AndroidRuntime(23397):    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:453)
04-20 18:56:05.441: E/AndroidRuntime(23397):    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:351)
04-20 18:56:05.441: E/AndroidRuntime(23397):    at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:171)
04-20 18:56:05.441: E/AndroidRuntime(23397):    at android.app.Dialog.show(Dialog.java:282)
04-20 18:56:05.441: E/AndroidRuntime(23397):    at com.band.seekersstop.EditInstantOpportunity$5.onTouch(EditInstantOpportunity.java:180)
04-20 18:56:05.441: E/AndroidRuntime(23397):    at android.view.View.dispatchTouchEvent(View.java:7193)
04-20 18:56:05.441: E/AndroidRuntime(23397):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2187)
04-20 18:56:05.441: E/AndroidRuntime(23397):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1888)
04-20 18:56:05.441: E/AndroidRuntime(23397):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2187)
04-20 18:56:05.441: E/AndroidRuntime(23397):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1888)
04-20 18:56:05.441: E/AndroidRuntime(23397):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2187)
04-20 18:56:05.441: E/AndroidRuntime(23397):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1888)
04-20 18:56:05.441: E/AndroidRuntime(23397):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2187)
04-20 18:56:05.441: E/AndroidRuntime(23397):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1888)
04-20 18:56:05.441: E/AndroidRuntime(23397):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2187)
04-20 18:56:05.441: E/AndroidRuntime(23397):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1888)
04-20 18:56:05.441: E/AndroidRuntime(23397):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2187)
04-20 18:56:05.441: E/AndroidRuntime(23397):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1888)
04-20 18:56:05.441: E/AndroidRuntime(23397):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2187)
04-20 18:56:05.441: E/AndroidRuntime(23397):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1888)
04-20 18:56:05.441: E/AndroidRuntime(23397):    at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2052)
04-20 18:56:05.441: E/AndroidRuntime(23397):    at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1506)
04-20 18:56:05.441: E/AndroidRuntime(23397):    at android.app.Activity.dispatchTouchEvent(Activity.java:2454)
04-20 18:56:05.441: E/AndroidRuntime(23397):    at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2000)
04-20 18:56:05.441: E/AndroidRuntime(23397):    at android.view.View.dispatchPointerEvent(View.java:7392)
04-20 18:56:05.441: E/AndroidRuntime(23397):    at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3539)
04-20 18:56:05.441: E/AndroidRuntime(23397):    at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3468)
04-20 18:56:05.441: E/AndroidRuntime(23397):    at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4577)
04-20 18:56:05.441: E/AndroidRuntime(23397):    at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4556)
04-20 18:56:05.441: E/AndroidRuntime(23397):    at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4652)
04-20 18:56:05.441: E/AndroidRuntime(23397):    at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:184)
04-20 18:56:05.441: E/AndroidRuntime(23397):    at android.os.MessageQueue.nativePollOnce(Native Method)
04-20 18:56:05.441: E/AndroidRuntime(23397):    at android.os.MessageQueue.next(MessageQueue.java:131)
04-20 18:56:05.441: E/AndroidRuntime(23397):    at android.os.Looper.loop(Looper.java:132)
04-20 18:56:05.441: E/AndroidRuntime(23397):    at android.app.ActivityThread.main(ActivityThread.java:5511)
04-20 18:56:05.441: E/AndroidRuntime(23397):    at java.lang.reflect.Method.invokeNative(Native Method)
04-20 18:56:05.441: E/AndroidRuntime(23397):    at java.lang.reflect.Method.invoke(Method.java:511)
04-20 18:56:05.441: E/AndroidRuntime(23397):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1029)
04-20 18:56:05.441: E/AndroidRuntime(23397):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:796)
04-20 18:56:05.441: E/AndroidRuntime(23397):    at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:2)

在你的onTouch方法中.. 使用YourActivityName.this而不是getApplicationContext()..或者如果你正在使用片段,只需调用getActivity()。