views:

56

answers:

1

Hi,

I am developing an application for the Parisian Metro. One of the functions is a map where you can click the metro stations and see what are the metro lines, and when are the next 4 trains on this station.

I have hence created a MapActivity and an ItemizedOverlay classes.

On my device it is working perfectly, but I am getting some logs from the users with a crash, and I really don't understand what's wrong.

My map activity adds ONE ItemizedOverlay that displays a blue dot for the current user location. This overlay also listens to onTap, which depending on the coordinates of the tap, will try to find metro stations (for which I know the lat/lon coordinates). This is working perfectly.

The stack trace of the crash is:

java.lang.NullPointerException
at com.google.android.maps.OverlayBundle.draw(OverlayBundle.java:42)
at com.google.android.maps.MapView.onDraw(MapView.java:494)
at android.view.View.draw(View.java:6535)
at android.view.ViewGroup.drawChild(ViewGroup.java:1531)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
at android.view.View.draw(View.java:6538)
at android.widget.FrameLayout.draw(FrameLayout.java:352)
at android.view.ViewGroup.drawChild(ViewGroup.java:1531)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
at android.view.View.draw(View.java:6538)
at android.widget.FrameLayout.draw(FrameLayout.java:352)
at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1830)
at android.view.ViewRoot.draw(ViewRoot.java:1349)
at android.view.ViewRoot.performTraversals(ViewRoot.java:1114)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1633)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4363)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)

Sometimes it comes from different lines but it always finishes crashing at OverlayBunde.java:42

As is does not mention my code, I don't know what's wrong.

You can get the source code of the MapActivity and the the ItemizedOverlay: http://code.google.com/p/metroparis/source/browse/trunk/src/org/bicou/metro/

The activity class is ACarteStations and the overlay class is StationMetroMapOverlay.

I am sorry that the code is in French. I will translate it eventually :) If you need translations about the variable names, just let me know.

Hope you can help me!!

A: 

I'm guessing that the following line (#106) in ajouterOverlayPosition() is the reason for your error:

if (l == null) {
        return null;
}

One thing that can happen is that the device fails in finding your location (at lm.getLastKnownLocation(...), line #73). In this case, you return null, and add that null to the mapOverlays at onCreate(). onDraw() tries to draw all the overlays, including this null overlay, and a NullPointerException is thrown.

You should probably treat the null location problem differently (perhaps show an error log, or try again, or use some default location...).

amitlicht
Thank you so much amitlicht! That was it! Smart guess. Sorry I took so long to reply, I had Internet problems. Thanks again.
Bicou