我正在尝试从布局 XML 文件获取资源setText()
。TextView
当用户点击谷歌地图中的标记时。这是我onTap()
为标记编写的代码。
直到我不添加TextView
,我的代码工作正常。当我单击标记并且一切正常时,它会显示对话框。
当我将这些行添加到时onTap()
,我运行应用程序并单击标记,它停止说Unfortunately map has stopped
。
我收到 LogCat 错误消息:
分派输入事件时出错
我创建了一个类 CustomOverlayItem 扩展 OverlayItem 类。Tv_descriptionTextView
是布局文件 cutom_dialog.xml 的一部分。
当用户单击标记时,如何在运行时动态setText()
调用?TextView
@Override
protected boolean onTap(int index) {
Dialog dialog = new Dialog(context, android.R.style.Theme_Dialog);
TextView tv_description = new TextView(context);
tv_description = (TextView) dialog.findViewById(R.id.tv2_description);
tv_description.setText("checking");
dialog.setContentView(R.layout.custom_dialog);
dialog.show();
return true;
}
这是 logcat 输出:
07-31 11:59:16.271: E/Trace(2143): error opening trace file: No such file or directory (2)
07-31 11:59:17.741: E/ZoomButtonsController(2143): Cannot make the zoom controller visible if the owner view is not attached to a window.
07-31 11:59:18.151: E/MapActivity(2143): Couldn't get connection factory client
07-31 11:59:28.531: E/InputEventReceiver(2143): Exception dispatching input event.
07-31 11:59:28.541: E/MessageQueue-JNI(2143): Exception in MessageQueue callback: handleReceiveCallback
07-31 11:59:28.591: E/MessageQueue-JNI(2143): java.lang.NullPointerException
07-31 11:59:28.591: E/MessageQueue-JNI(2143): at com.incubers.map.Markers.onTap(Markers.java:41)
07-31 11:59:28.591: E/MessageQueue-JNI(2143): at com.google.android.maps.ItemizedOverlay.onTap(ItemizedOverlay.java:453)
07-31 11:59:28.591: E/MessageQueue-JNI(2143): at com.google.android.maps.OverlayBundle.onTap(OverlayBundle.java:83)
07-31 11:59:28.591: E/MessageQueue-JNI(2143): at com.google.android.maps.MapView$1.onSingleTapUp(MapView.java:356)
07-31 11:59:28.591: E/MessageQueue-JNI(2143): at com.google.android.maps.GestureDetector.onTouchEvent(GestureDetector.java:533)
07-31 11:59:28.591: E/MessageQueue-JNI(2143): at com.google.android.maps.MapView.onTouchEvent(MapView.java:683)
07-31 11:59:28.591: E/MessageQueue-JNI(2143): at android.view.View.dispatchTouchEvent(View.java:7127)
07-31 11:59:28.591: E/MessageQueue-JNI(2143): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2170)
07-31 11:59:28.591: E/MessageQueue-JNI(2143): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1905)
07-31 11:59:28.591: E/MessageQueue-JNI(2143): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
07-31 11:59:28.591: E/MessageQueue-JNI(2143): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
07-31 11:59:28.591: E/MessageQueue-JNI(2143): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
07-31 11:59:28.591: E/MessageQueue-JNI(2143): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
07-31 11:59:28.591: E/MessageQueue-JNI(2143): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
07-31 11:59:28.591: E/MessageQueue-JNI(2143): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
07-31 11:59:28.591: E/MessageQueue-JNI(2143): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
07-31 11:59:28.591: E/MessageQueue-JNI(2143): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
07-31 11:59:28.591: E/MessageQueue-JNI(2143): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1925)
07-31 11:59:28.591: E/MessageQueue-JNI(2143): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1379)
07-31 11:59:28.591: E/MessageQueue-JNI(2143): at android.app.Activity.dispatchTouchEvent(Activity.java:2396)
07-31 11:59:28.591: E/MessageQueue-JNI(2143): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1873)
07-31 11:59:28.591: E/MessageQueue-JNI(2143): at android.view.View.dispatchPointerEvent(View.java:7307)
07-31 11:59:28.591: E/MessageQueue-JNI(2143): at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3172)
07-31 11:59:28.591: E/MessageQueue-JNI(2143): at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3117)
07-31 11:59:28.591: E/MessageQueue-JNI(2143): at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4153)
07-31 11:59:28.591: E/MessageQueue-JNI(2143): at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4132)
07-31 11:59:28.591: E/MessageQueue-JNI(2143): at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4224)
07-31 11:59:28.591: E/MessageQueue-JNI(2143): at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:171)
07-31 11:59:28.591: E/MessageQueue-JNI(2143): at android.os.MessageQueue.nativePollOnce(Native Method)
07-31 11:59:28.591: E/MessageQueue-JNI(2143): at android.os.MessageQueue.next(MessageQueue.java:125)
07-31 11:59:28.591: E/MessageQueue-JNI(2143): at android.os.Looper.loop(Looper.java:124)
07-31 11:59:28.591: E/MessageQueue-JNI(2143): at android.app.ActivityThread.main(ActivityThread.java:4745)
07-31 11:59:28.591: E/MessageQueue-JNI(2143): at java.lang.reflect.Method.invokeNative(Native Method)
07-31 11:59:28.591: E/MessageQueue-JNI(2143): at java.lang.reflect.Method.invoke(Method.java:511)
07-31 11:59:28.591: E/MessageQueue-JNI(2143): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
07-31 11:59:28.591: E/MessageQueue-JNI(2143): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-31 11:59:28.591: E/MessageQueue-JNI(2143): at dalvik.system.NativeStart.main(Native Method)
07-31 11:59:28.681: E/AndroidRuntime(2143): FATAL EXCEPTION: main
07-31 11:59:28.681: E/AndroidRuntime(2143): java.lang.NullPointerException
07-31 11:59:28.681: E/AndroidRuntime(2143): at com.incubers.map.Markers.onTap(Markers.java:41)
07-31 11:59:28.681: E/AndroidRuntime(2143): at com.google.android.maps.ItemizedOverlay.onTap(ItemizedOverlay.java:453)
07-31 11:59:28.681: E/AndroidRuntime(2143): at com.google.android.maps.OverlayBundle.onTap(OverlayBundle.java:83)
07-31 11:59:28.681: E/AndroidRuntime(2143): at com.google.android.maps.MapView$1.onSingleTapUp(MapView.java:356)
07-31 11:59:28.681: E/AndroidRuntime(2143): at com.google.android.maps.GestureDetector.onTouchEvent(GestureDetector.java:533)
07-31 11:59:28.681: E/AndroidRuntime(2143): at com.google.android.maps.MapView.onTouchEvent(MapView.java:683)
07-31 11:59:28.681: E/AndroidRuntime(2143): at android.view.View.dispatchTouchEvent(View.java:7127)
07-31 11:59:28.681: E/AndroidRuntime(2143): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2170)
07-31 11:59:28.681: E/AndroidRuntime(2143): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1905)
07-31 11:59:28.681: E/AndroidRuntime(2143): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
07-31 11:59:28.681: E/AndroidRuntime(2143): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
07-31 11:59:28.681: E/AndroidRuntime(2143): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
07-31 11:59:28.681: E/AndroidRuntime(2143): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
07-31 11:59:28.681: E/AndroidRuntime(2143): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
07-31 11:59:28.681: E/AndroidRuntime(2143): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
07-31 11:59:28.681: E/AndroidRuntime(2143): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
07-31 11:59:28.681: E/AndroidRuntime(2143): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
07-31 11:59:28.681: E/AndroidRuntime(2143): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1925)
07-31 11:59:28.681: E/AndroidRuntime(2143): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1379)
07-31 11:59:28.681: E/AndroidRuntime(2143): at android.app.Activity.dispatchTouchEvent(Activity.java:2396)
07-31 11:59:28.681: E/AndroidRuntime(2143): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1873)
07-31 11:59:28.681: E/AndroidRuntime(2143): at android.view.View.dispatchPointerEvent(View.java:7307)
07-31 11:59:28.681: E/AndroidRuntime(2143): at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3172)
07-31 11:59:28.681: E/AndroidRuntime(2143): at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3117)
07-31 11:59:28.681: E/AndroidRuntime(2143): at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4153)
07-31 11:59:28.681: E/AndroidRuntime(2143): at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4132)
07-31 11:59:28.681: E/AndroidRuntime(2143): at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4224)
07-31 11:59:28.681: E/AndroidRuntime(2143): at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:171)
07-31 11:59:28.681: E/AndroidRuntime(2143): at android.os.MessageQueue.nativePollOnce(Native Method)
07-31 11:59:28.681: E/AndroidRuntime(2143): at android.os.MessageQueue.next(MessageQueue.java:125)
07-31 11:59:28.681: E/AndroidRuntime(2143): at android.os.Looper.loop(Looper.java:124)
07-31 11:59:28.681: E/AndroidRuntime(2143): at android.app.ActivityThread.main(ActivityThread.java:4745)
07-31 11:59:28.681: E/AndroidRuntime(2143): at java.lang.reflect.Method.invokeNative(Native Method)
07-31 11:59:28.681: E/AndroidRuntime(2143): at java.lang.reflect.Method.invoke(Method.java:511)
07-31 11:59:28.681: E/AndroidRuntime(2143): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
07-31 11:59:28.681: E/AndroidRuntime(2143): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-31 11:59:28.681: E/AndroidRuntime(2143): at dalvik.system.NativeStart.main(Native Method)