tags:

views:

19

answers:

2

Hi, 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
A: 

Could you include the relevant logcat?

Anders Haglund
A: 

The itemized overlay needs the 2nd 2 paramters because it uses them for click events. When you click one of the itemized overlays, it has a title and a description associated with it, which are the 2nd and 3rd parameters in your overlay item

Falmarri
The itemized overlay works but only if I add a random point onCreate of the mapview else it crashes
Jason
Oh I misunderstood. What's your question then? Your post is really confusing. Can you post the exact code that works, and then the exact code that doesn't?
Falmarri
Its a mess to post the exact code becuse its in a few files. Basicly if i Make an iteized Overlay And add it to the Overlays of the map without adding a Overlay Item before adding it to the overlays of the map. then when I try create a new overlayItem (I am doing it on the onTap Method) then the application crashes as posted.
Jason
Why do you need to add an itemized overlay without any overlay items to a map?
Falmarri
Just until the user presses the map then the Item goes to that location
Jason
Are you sure you have the overlayitem and mapoverlay classes correct? It can be super confusing about which overlay you're adding stuff to
Falmarri