Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when opening map. NullPointerException #1223

Open
panovvitalik opened this issue Dec 4, 2018 · 14 comments

Comments

Projects
None yet
4 participants
@panovvitalik
Copy link

commented Dec 4, 2018

Caused by: java.lang.NullPointerException:
at org.osmdroid.views.MapViewRepository.getDefaultMarkerIcon (MapViewRepository.java:71)
at org.osmdroid.views.overlay.Marker.setDefaultIcon (Marker.java:139)
at org.osmdroid.views.overlay.Marker. (Marker.java:114)
at org.osmdroid.views.overlay.Marker. (Marker.java:92)
at vitalypanov.phototracker.utils.MapOpenStreetUtils$BaseMarker. (MapOpenStreetUtils.java:64)

Issue Type

[ ] Question
[ x] Bug
[ ] Improvement
[ ] Build system related
[ ] Performance
[ ] Documentation

Description and/or steps/code to reproduce the problem

Sometimes occure when showing map

Environment

If it's a bug, version(s) of android this affects:

All

Version of osmdroid the issue relates to:

6.0.3

@panovvitalik

This comment has been minimized.

Copy link
Author

commented Dec 4, 2018

Crash occurred at this variable:
private MapViewRepository mMapViewRepository;
Unfortuntely it's declared as private and I cant acces it and check for null value in super class :(

@panovvitalik

This comment has been minimized.

Copy link
Author

commented Dec 4, 2018

The only way I see now, to fix this crash is extends Marker class
and ovveride method:
`
@override
public void setDefaultIcon() {

        // mIcon = mMapViewRepository.getDefaultMarkerIcon();

        setAnchor(ANCHOR_CENTER, ANCHOR_BOTTOM);
    }`

Is line "mIcon = mMapViewRepository.getDefaultMarkerIcon();" is critical?
I checked my map is working without this line correctly, but I dont know what else depends of this line of code?

p.s.
In Marker constructor I see next line below setDefaultIcon calling:
setInfoWindow(mMapViewRepository.getDefaultMarkerInfoWindow());
It will crash there next time :( if mMapViewRepository is null
I dont know how can I fix this bug :( Please help

@panovvitalik

This comment has been minimized.

Copy link
Author

commented Dec 4, 2018

Ohhh :( next idea for fixing this bug, I get full code of Marker class to my project and rewrite constructor and setDefaultIcon method and some other short changes to point on my class, not on Marker.
Very terrible solution but I have no other idea to fix it. Main code for fixing the bug is below:

p.s. It's not correctly working. Now it crashes in other classes which refrence to marker and expect Marker class not mine :(((

public class BaseMarker extends OverlayWithIW {
...
public BaseMarker(MapView mapView, final Context resourceProxy) {
super();
if (!Utils.isNull(mapView)) {
mMapViewRepository = mapView.getRepository();
}
if (!Utils.isNull(mapView.getContext())) {
mResources = mapView.getContext().getResources();
}
mBearing = 0.0f;
mAlpha = 1.0f; //opaque
mPosition = new GeoPoint(0.0, 0.0);
mAnchorU = ANCHOR_CENTER;
mAnchorV = ANCHOR_CENTER;
mIWAnchorU = ANCHOR_CENTER;
mIWAnchorV = ANCHOR_TOP;
mDraggable = false;
mIsDragged = false;
mPositionPixels = new Point();
mPanToView = true;
mDragOffsetY = 0.0f;
mFlat = false; //billboard
mOnMarkerClickListener = null;
mOnMarkerDragListener = null;
setDefaultIcon();
if (!Utils.isNull(mMapViewRepository)) {
setInfoWindow(mMapViewRepository.getDefaultMarkerInfoWindow());
}
}
...
public void setDefaultIcon() {
if (!Utils.isNull(mMapViewRepository)) {
mIcon = mMapViewRepository.getDefaultMarkerIcon();
}
setAnchor(ANCHOR_CENTER, ANCHOR_BOTTOM);
}
....
}

@monsieurtanuki

This comment has been minimized.

Copy link
Collaborator

commented Dec 4, 2018

I don't know the context of this issue, and I can tell you that I can see Marker default icons in my tests.
How do you get this bug?

mRepository cannot be null, cf. MapView:

private final MapViewRepository mRepository = new MapViewRepository(this);

"at org.osmdroid.views.MapViewRepository.getDefaultMarkerIcon (MapViewRepository.java:71)" is

mDefaultMarkerIcon = mMapView.getContext().getResources().getDrawable(R.drawable.marker_default);

mMapView cannot be null, unless you call mMapView.onDetach(). Do you call this onDetach method and expect the map view to work afterwards?

@panovvitalik

This comment has been minimized.

Copy link
Author

commented Dec 4, 2018

I don't know the context of this issue, and I can tell you that I can see Marker default icons in my tests.
How do you get this bug?

I get it from end users. I can't reproduce it directly, it occure from time to time in production app.


`mMapView` cannot be `null`, unless you call `mMapView.onDetach()`. Do you call this `onDetach` method and expect the map view to work afterwards?

Of course I'm not creating Marker objects in onDetach method.

@monsieurtanuki

This comment has been minimized.

Copy link
Collaborator

commented Dec 4, 2018

Are you creating Markers after onDetach has been called?

@panovvitalik

This comment has been minimized.

Copy link
Author

commented Dec 4, 2018

Are you creating Markers after onDetach has been called?

No

@panovvitalik

This comment has been minimized.

Copy link
Author

commented Dec 4, 2018

It looks like release 6.0.3 is unstable :( (at least in my app)
This is not the only one bug that was found :(
I rolled back to 6.0.2.

@monsieurtanuki

This comment has been minimized.

Copy link
Collaborator

commented Dec 4, 2018

@panovvitalik If you want the bug to be fixed, I suggest that you create a mini app where you reproduce the bug.

@panovvitalik

This comment has been minimized.

Copy link
Author

commented Dec 4, 2018

@panovvitalik If you want the bug to be fixed, I suggest that you create a mini app where you reproduce the bug.

I can't reproduce this bug on developer machine as I mentioned above.
It occure in production env. from time to time.
I can provide full crash stack only if it helps to find out the solution.
For example:

Today, 1:59 PM on app version 136
Xiaomi Redmi Note 5A (ugg), Android 7.1
Report 1 of 1
java.lang.RuntimeException:
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2755)
at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2816)
at android.app.ActivityThread.handleRelaunchActivity (ActivityThread.java:4651)
at android.app.ActivityThread.-wrap19 (ActivityThread.java)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1563)
at android.os.Handler.dispatchMessage (Handler.java:102)
at android.os.Looper.loop (Looper.java:163)
at android.app.ActivityThread.main (ActivityThread.java:6383)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:794)
Caused by: java.lang.NullPointerException:
at org.osmdroid.views.MapViewRepository.getDefaultMarkerIcon (MapViewRepository.java:71)
at org.osmdroid.views.overlay.Marker.setDefaultIcon (Marker.java:139)
at org.osmdroid.views.overlay.Marker. (Marker.java:114)
at org.osmdroid.views.overlay.Marker. (Marker.java:92)
at vitalypanov.phototracker.utils.MapOpenStreetUtils$BaseMarker. (MapOpenStreetUtils.java:64)
at vitalypanov.phototracker.utils.MapOpenStreetUtils$UserMarker. (MapOpenStreetUtils.java:87)
at vitalypanov.phototracker.utils.MapOpenStreetUtils$DistanceMarker. (MapOpenStreetUtils.java:94)
at vitalypanov.phototracker.utils.MapOpenStreetUtils.getDistanceMarkers (MapOpenStreetUtils.java:265)
at vitalypanov.phototracker.utils.MapOpenStreetUtils.addTrackData (MapOpenStreetUtils.java:318)
at vitalypanov.phototracker.fragment.MapOpenStreetSupportFragment.reloadTrackData (MapOpenStreetSupportFragment.java:522)
at vitalypanov.phototracker.fragment.MapOpenStreetSupportFragment.access$1500 (MapOpenStreetSupportFragment.java:97)
at vitalypanov.phototracker.fragment.MapOpenStreetSupportFragment$21$1.run (MapOpenStreetSupportFragment.java:947)
at android.app.Activity.runOnUiThread (Activity.java:6040)
at vitalypanov.phototracker.fragment.MapOpenStreetSupportFragment$21.onActivityEnabled (MapOpenStreetSupportFragment.java:944)
at vitalypanov.phototracker.fragment.BaseFragment.onAttach (BaseFragment.java:29)
at android.support.v4.app.Fragment.onAttach (Fragment.java:1422)
at vitalypanov.phototracker.fragment.BaseFragment.onAttach (BaseFragment.java:36)
at android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManager.java:1404)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState (FragmentManager.java:1784)
at android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManager.java:1852)
at android.support.v4.app.FragmentManagerImpl.dispatchStateChange (FragmentManager.java:3269)
at android.support.v4.app.FragmentManagerImpl.dispatchCreate (FragmentManager.java:3223)
at android.support.v4.app.FragmentController.dispatchCreate (FragmentController.java:190)
at android.support.v4.app.FragmentActivity.onCreate (FragmentActivity.java:369)
at android.support.v7.app.AppCompatActivity.onCreate (AppCompatActivity.java:85)
at vitalypanov.phototracker.activity.RunningTrackPagerActivity.onCreate (RunningTrackPagerActivity.java:58)
at android.app.Activity.performCreate (Activity.java:6861)
at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2708)

@spyhunter99

This comment has been minimized.

Copy link
Collaborator

commented Dec 4, 2018

on detach is also called when the activity is recycled, such as changing activities, device rotation, etc. could that be a factor?

@panovvitalik

This comment has been minimized.

Copy link
Author

commented Dec 5, 2018

on detach is also called when the activity is recycled, such as changing activities, device rotation, etc. could that be a factor?

I think, it could!
But the quesstion is - how I can fix it? (besides rolling back to prev. version 6.0.2)

@mueller-ma

This comment has been minimized.

Copy link

commented Jun 1, 2019

Same here:

06-01 21:33:04.044 org.openhab.habdroid.beta E/AndroidRuntime: FATAL EXCEPTION: main
    Process: org.openhab.habdroid.beta, PID: 9943
    java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context org.osmdroid.views.MapView.getContext()' on a null object reference
        at org.osmdroid.views.MapViewRepository.getDefaultMarkerIcon(MapViewRepository.java:74)
        at org.osmdroid.views.overlay.Marker.setDefaultIcon(Marker.java:139)
        at org.osmdroid.views.overlay.Marker.<init>(Marker.java:114)
        at org.osmdroid.views.overlay.Marker.<init>(Marker.java:92)
        at org.openhab.habdroid.ui.MapViewHelper$OsmViewHolder.setMarker(MapViewHelper.java:230)

spyhunter99 added a commit that referenced this issue Jun 1, 2019

@spyhunter99 spyhunter99 added the bug label Jun 1, 2019

@spyhunter99 spyhunter99 added this to the v6.1.1 milestone Jun 1, 2019

@spyhunter99

This comment has been minimized.

Copy link
Collaborator

commented Jun 1, 2019

i just added some NPE checks and updated the javadocs. Snapshots have been updated too. Can you try and reproduce the issue? I fear this commit will only reveal other issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.