第 102 行和第 104 行空异常
我认为 imageView 和 textView id 有问题。
布局:
activity_main.xml
还有custom_view.xml
——有imageView和textView。
代码:
protected Dialog onCreateDialog(int id) {
Dialog dialog = null;
switch(id) {
case 0:
dialog = new Dialog(this);
dialog.setContentView(R.layout.activity_main);
dialog.setTitle("Custom Dialog");
ImageView image = (ImageView) dialog.findViewById(R.id.image);
//102: image.setImageResource(R.drawable.android);
TextView text = (TextView)dialog.findViewById(R.id.text);
//104: text.setText(");
break;
}
return dialog;
}
日志:
10-03 02:41:00.929: D/gralloc_goldfish(4372): Emulator without GPU emulation detected.
10-03 02:47:07.159: D/gralloc_goldfish(4415): Emulator without GPU emulation detected.
10-03 02:47:16.529: E/InputEventReceiver(4415): Exception dispatching input event.
10-03 02:47:16.529: E/MessageQueue-JNI(4415): Exception in MessageQueue callback: handleReceiveCallback
10-03 02:47:17.109: E/MessageQueue-JNI(4415): java.lang.NullPointerException
10-03 02:47:17.109: E/MessageQueue-JNI(4415): at com.example.hw3_new.MainActivity.onCreateDialog(MainActivity.java:102)
10-03 02:47:17.109: E/MessageQueue-JNI(4415): at android.app.Activity.onCreateDialog(Activity.java:2989)
10-03 02:47:17.109: E/MessageQueue-JNI(4415): at android.app.Activity.createDialog(Activity.java:976)
10-03 02:47:17.109: E/MessageQueue-JNI(4415): at android.app.Activity.showDialog(Activity.java:3082)
10-03 02:47:17.109: E/MessageQueue-JNI(4415): at android.app.Activity.showDialog(Activity.java:3041)
10-03 02:47:17.109: E/MessageQueue-JNI(4415): at com.example.hw3_new.MainActivity$CustomView.onTouchEvent(MainActivity.java:64)
10-03 02:47:17.109: E/MessageQueue-JNI(4415): at android.view.View.dispatchTouchEvent(View.java:7384)
10-03 02:47:17.109: E/MessageQueue-JNI(4415): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2209)
10-03 02:47:17.109: E/MessageQueue-JNI(4415): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1910)
10-03 02:47:17.109: E/MessageQueue-JNI(4415): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2209)
10-03 02:47:17.109: E/MessageQueue-JNI(4415): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1910)
10-03 02:47:17.109: E/MessageQueue-JNI(4415): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2209)
10-03 02:47:17.109: E/MessageQueue-JNI(4415): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1910)
10-03 02:47:17.109: E/MessageQueue-JNI(4415): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1966)
10-03 02:47:17.109: E/MessageQueue-JNI(4415): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1418)
10-03 02:47:17.109: E/MessageQueue-JNI(4415): at android.app.Activity.dispatchTouchEvent(Activity.java:2424)
10-03 02:47:17.109: E/MessageQueue-JNI(4415): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1914)
10-03 02:47:17.109: E/MessageQueue-JNI(4415): at android.view.View.dispatchPointerEvent(View.java:7564)
10-03 02:47:17.109: E/MessageQueue-JNI(4415): at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:3883)
10-03 02:47:17.109: E/MessageQueue-JNI(4415): at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3778)
10-03 02:47:17.109: E/MessageQueue-JNI(4415): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
10-03 02:47:17.109: E/MessageQueue-JNI(4415): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3429)
10-03 02:47:17.109: E/MessageQueue-JNI(4415): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3398)
10-03 02:47:17.109: E/MessageQueue-JNI(4415): at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3483)
10-03 02:47:17.109: E/MessageQueue-JNI(4415): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3406)
10-03 02:47:17.109: E/MessageQueue-JNI(4415): at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3540)
10-03 02:47:17.109: E/MessageQueue-JNI(4415): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
10-03 02:47:17.109: E/MessageQueue-JNI(4415): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3429)
10-03 02:47:17.109: E/MessageQueue-JNI(4415): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3398)
10-03 02:47:17.109: E/MessageQueue-JNI(4415): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3406)
10-03 02:47:17.109: E/MessageQueue-JNI(4415): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
10-03 02:47:17.109: E/MessageQueue-JNI(4415): at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5419)
10-03 02:47:17.109: E/MessageQueue-JNI(4415): at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5399)
10-03 02:47:17.109: E/MessageQueue-JNI(4415): at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5370)
10-03 02:47:17.109: E/MessageQueue-JNI(4415): at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5493)
10-03 02:47:17.109: E/MessageQueue-JNI(4415): at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:182)
10-03 02:47:17.109: E/MessageQueue-JNI(4415): at android.os.MessageQueue.nativePollOnce(Native Method)
10-03 02:47:17.109: E/MessageQueue-JNI(4415): at android.os.MessageQueue.next(MessageQueue.java:132)
10-03 02:47:17.109: E/MessageQueue-JNI(4415): at android.os.Looper.loop(Looper.java:124)
10-03 02:47:17.109: E/MessageQueue-JNI(4415): at android.app.ActivityThread.main(ActivityThread.java:5103)
10-03 02:47:17.109: E/MessageQueue-JNI(4415): at java.lang.reflect.Method.invokeNative(Native Method)
10-03 02:47:17.109: E/MessageQueue-JNI(4415): at java.lang.reflect.Method.invoke(Method.java:525)
10-03 02:47:17.109: E/MessageQueue-JNI(4415): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
10-03 02:47:17.109: E/MessageQueue-JNI(4415): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-03 02:47:17.109: E/MessageQueue-JNI(4415): at dalvik.system.NativeStart.main(Native Method)
10-03 02:47:17.140: D/AndroidRuntime(4415): Shutting down VM
10-03 02:47:17.140: W/dalvikvm(4415): threadid=1: thread exiting with uncaught exception (group=0x414c4700)
10-03 02:47:17.550: E/AndroidRuntime(4415): FATAL EXCEPTION: main
10-03 02:47:17.550: E/AndroidRuntime(4415): java.lang.NullPointerException
10-03 02:47:17.550: E/AndroidRuntime(4415): at com.example.hw3_new.MainActivity.onCreateDialog(MainActivity.java:102)
10-03 02:47:17.550: E/AndroidRuntime(4415): at android.app.Activity.onCreateDialog(Activity.java:2989)
10-03 02:47:17.550: E/AndroidRuntime(4415): at android.app.Activity.createDialog(Activity.java:976)
10-03 02:47:17.550: E/AndroidRuntime(4415): at android.app.Activity.showDialog(Activity.java:3082)
10-03 02:47:17.550: E/AndroidRuntime(4415): at android.app.Activity.showDialog(Activity.java:3041)
10-03 02:47:17.550: E/AndroidRuntime(4415): at com.example.hw3_new.MainActivity$CustomView.onTouchEvent(MainActivity.java:64)
10-03 02:47:17.550: E/AndroidRuntime(4415): at android.view.View.dispatchTouchEvent(View.java:7384)
10-03 02:47:17.550: E/AndroidRuntime(4415): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2209)
10-03 02:47:17.550: E/AndroidRuntime(4415): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1910)
10-03 02:47:17.550: E/AndroidRuntime(4415): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2209)
10-03 02:47:17.550: E/AndroidRuntime(4415): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1910)
10-03 02:47:17.550: E/AndroidRuntime(4415): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2209)
10-03 02:47:17.550: E/AndroidRuntime(4415): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1910)
10-03 02:47:17.550: E/AndroidRuntime(4415): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1966)
10-03 02:47:17.550: E/AndroidRuntime(4415): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1418)
10-03 02:47:17.550: E/AndroidRuntime(4415): at android.app.Activity.dispatchTouchEvent(Activity.java:2424)
10-03 02:47:17.550: E/AndroidRuntime(4415): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1914)
10-03 02:47:17.550: E/AndroidRuntime(4415): at android.view.View.dispatchPointerEvent(View.java:7564)
10-03 02:47:17.550: E/AndroidRuntime(4415): at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:3883)
10-03 02:47:17.550: E/AndroidRuntime(4415): at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3778)
10-03 02:47:17.550: E/AndroidRuntime(4415): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
10-03 02:47:17.550: E/AndroidRuntime(4415): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3429)
10-03 02:47:17.550: E/AndroidRuntime(4415): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3398)
10-03 02:47:17.550: E/AndroidRuntime(4415): at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3483)
10-03 02:47:17.550: E/AndroidRuntime(4415): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3406)
10-03 02:47:17.550: E/AndroidRuntime(4415): at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3540)
10-03 02:47:17.550: E/AndroidRuntime(4415): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
10-03 02:47:17.550: E/AndroidRuntime(4415): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3429)
10-03 02:47:17.550: E/AndroidRuntime(4415): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3398)
10-03 02:47:17.550: E/AndroidRuntime(4415): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3406)
10-03 02:47:17.550: E/AndroidRuntime(4415): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
10-03 02:47:17.550: E/AndroidRuntime(4415): at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5419)
10-03 02:47:17.550: E/AndroidRuntime(4415): at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5399)
10-03 02:47:17.550: E/AndroidRuntime(4415): at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5370)
10-03 02:47:17.550: E/AndroidRuntime(4415): at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5493)
10-03 02:47:17.550: E/AndroidRuntime(4415): at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:182)
10-03 02:47:17.550: E/AndroidRuntime(4415): at android.os.MessageQueue.nativePollOnce(Native Method)
10-03 02:47:17.550: E/AndroidRuntime(4415): at android.os.MessageQueue.next(MessageQueue.java:132)
10-03 02:47:17.550: E/AndroidRuntime(4415): at android.os.Looper.loop(Looper.java:124)
10-03 02:47:17.550: E/AndroidRuntime(4415): at android.app.ActivityThread.main(ActivityThread.java:5103)
10-03 02:47:17.550: E/AndroidRuntime(4415): at java.lang.reflect.Method.invokeNative(Native Method)
10-03 02:47:17.550: E/AndroidRuntime(4415): at java.lang.reflect.Method.invoke(Method.java:525)
10-03 02:47:17.550: E/AndroidRuntime(4415): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
10-03 02:47:17.550: E/AndroidRuntime(4415): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-03 02:47:17.550: E/AndroidRuntime(4415): at dalvik.system.NativeStart.main(Native Method)
10-03 02:47:17.769: D/dalvikvm(4415): GC_FOR_ALLOC freed 348K, 16% free 2671K/3176K, paused 110ms, total 120ms
10-03 02:47:21.018: I/Process(4415): Sending signal. PID: 4415 SIG: 9