Issue
I am trying to setText()
to a TextView
resource from a layout XML file.
when user clicks on a marker in Google map. This is the code that I've written in onTap()
for a marker.
Till I don't add TextView
, my code works fine. It shows the dialog when I click the marker and everything works.
When I add these lines to onTap()
, I run the application and click on marker and it stops saying Unfortunately map has stopped
.
I am getting LogCat error message:
Error dispatching input event
I have created a class CustomOverlayItem extending OverlayItem class. Tv_description TextView
is part of layout file cutom_dialog.xml.
How can I call setText()
to the TextView
dynamically at the run time when user clicks marker?
@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;
}
Here is the logcat output :
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)
Solution
I believe this line is wrong.
tv_description = (TextView) dialog.findViewById(R.id.tv2_description);
You are trying to find a TextView
which is not present in your dialog.
Your dialog is a default Dialog
which will not have this TextView
. Do a setContentView()
on your dialog with a layout, that has this TextView
, before this above line.
Answered By - nandeesh
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.