Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with crash with ItemizedOverlay

Tags:

android

I have been trying for hours to figure out why I can not use an Itemized Map overlay without doing this before adding it to the ovelays of the map:

GeoPoint point; OverlayItem overlayitem = new OverlayItem(point, "",""); MarkerOverlay.addOverlay(overlayitem);

If i try to do this without the MarkerOverlay.addOverlay(overlayitem); command then when i try to add a new overLay like so:

public boolean onTap(GeoPoint point, MapView mapView)
{
    if (mOverlays.size() > 0)
        mOverlays.remove(0);
    OverlayItem overlayitem = new OverlayItem(point, "", "");
    mOverlays.add(overlay);
    populate();
    return true;
}

Inside my ItemizedOverlay class then i Just get a null reference exeption (I have no idea when or why - It says its no source code available when in debug)

Any Ideas?

EDIT: This is what I can find in the logcat :

09-20 22:36:22.164: WARN/dalvikvm(311): threadid=3: thread exiting with uncaught exception (group=0x4001b188)

and this is what I believe to be the infamous exception:

   09-20 22:36:22.293: ERROR/AndroidRuntime(311): java.lang.NullPointerException
09-20 22:36:22.293: ERROR/AndroidRuntime(311):     at com.google.android.maps.ItemizedOverlay.getItemsAtLocation(ItemizedOverlay.java:617)
09-20 22:36:22.293: ERROR/AndroidRuntime(311):     at com.google.android.maps.ItemizedOverlay.getItemAtLocation(ItemizedOverlay.java:586)
09-20 22:36:22.293: ERROR/AndroidRuntime(311):     at com.google.android.maps.ItemizedOverlay.handleMotionEvent(ItemizedOverlay.java:498)
09-20 22:36:22.293: ERROR/AndroidRuntime(311):     at com.google.android.maps.ItemizedOverlay.onTouchEvent(ItemizedOverlay.java:572)
09-20 22:36:22.293: ERROR/AndroidRuntime(311):     at com.google.android.maps.OverlayBundle.onTouchEvent(OverlayBundle.java:63)
09-20 22:36:22.293: ERROR/AndroidRuntime(311):     at com.google.android.maps.MapView.onTouchEvent(MapView.java:625)
09-20 22:36:22.293: ERROR/AndroidRuntime(311):     at android.view.View.dispatchTouchEvent(View.java:3709)
09-20 22:36:22.293: ERROR/AndroidRuntime(311):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:852)
09-20 22:36:22.293: ERROR/AndroidRuntime(311):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:822)
09-20 22:36:22.293: ERROR/AndroidRuntime(311):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:822)
09-20 22:36:22.293: ERROR/AndroidRuntime(311):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:822)
09-20 22:36:22.293: ERROR/AndroidRuntime(311):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
09-20 22:36:22.293: ERROR/AndroidRuntime(311):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
09-20 22:36:22.293: ERROR/AndroidRuntime(311):     at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
09-20 22:36:22.293: ERROR/AndroidRuntime(311):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
09-20 22:36:22.293: ERROR/AndroidRuntime(311):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
09-20 22:36:22.293: ERROR/AndroidRuntime(311):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-20 22:36:22.293: ERROR/AndroidRuntime(311):     at android.os.Looper.loop(Looper.java:123)
09-20 22:36:22.293: ERROR/AndroidRuntime(311):     at android.app.ActivityThread.main(ActivityThread.java:4363)
09-20 22:36:22.293: ERROR/AndroidRuntime(311):     at java.lang.reflect.Method.invokeNative(Native Method)
09-20 22:36:22.293: ERROR/AndroidRuntime(311):     at java.lang.reflect.Method.invoke(Method.java:521)
09-20 22:36:22.293: ERROR/AndroidRuntime(311):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
09-20 22:36:22.293: ERROR/AndroidRuntime(311):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
09-20 22:36:22.293: ERROR/AndroidRuntime(311):     at dalvik.system.NativeStart.main(Native Method)
09-20 22:36:22.394: ERROR/dalvikvm(311): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
like image 896
Jason Avatar asked Sep 20 '10 22:09

Jason


1 Answers

I recently came across this problem. The issue is outlined in this bug report.

To fix it you should call populate() in your ItemizedOverlay before any data is populated. I added it to the constructor:

private class MyItemizedOverlay extends ItemizedOverlay<OverlayItem> {

    private Context context;
    private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();

    LocationItemizedOverlay(Drawable defaultMarker, Context context) {
        super(boundCenterBottom(defaultMarker));
        this.context = context;
        populate(); // Add this
    }
}
like image 155
Che Avatar answered Nov 17 '22 20:11

Che