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

tap on map cause an app crash on android #372

Open
wendt88 opened this issue Jun 25, 2020 · 6 comments
Open

tap on map cause an app crash on android #372

wendt88 opened this issue Jun 25, 2020 · 6 comments

Comments

@wendt88
Copy link

wendt88 commented Jun 25, 2020

tns info

√ Getting NativeScript components versions information...
√ Component nativescript has 6.7.6 version and is up to date.
√ Component @nativescript/core has 6.5.8 version and is up to date.
√ Component tns-android has 6.5.1 version and is up to date.
√ Component tns-ios has 6.5.1 version and is up to date.

nativescript-mapbox: 5.0.1

if you tap lightly on the over side of the marker (default marker)
ezgif com-video-to-gif

error

An uncaught Exception occurred on "main" thread.
Attempt to invoke virtual method 'boolean java.lang.Boolean.booleanValue()' on a null object reference

StackTrace:
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Boolean.booleanValue()' on a null object reference
	at com.tns.gen.com.mapbox.mapboxsdk.maps.MapboxMap_OnMapClickListener.onMapClick(MapboxMap_OnMapClickListener.java:19)
	at com.mapbox.mapboxsdk.maps.MapGestureDetector.notifyOnMapClickListeners(MapGestureDetector.java:983)
	at com.mapbox.mapboxsdk.maps.MapGestureDetector$StandardGestureListener.onSingleTapConfirmed(MapGestureDetector.java:358)
	at com.mapbox.android.gestures.StandardGestureDetector$1.onSingleTapConfirmed(StandardGestureDetector.java:81)
	at android.view.GestureDetector$GestureHandler.handleMessage(GestureDetector.java:323)
	at android.os.Handler.dispatchMessage(Handler.java:107)
	at android.os.Looper.loop(Looper.java:214)
	at android.app.ActivityThread.main(ActivityThread.java:7356)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
@TPham92
Copy link

TPham92 commented Jul 6, 2020

Any updates on this issue?

@Yermo
Copy link
Owner

Yermo commented Jul 6, 2020

I haven't had a chance to look at it. At my present rate of progress I'll be making another major pass through the plugin in early August.

@TPham92
Copy link

TPham92 commented Jul 8, 2020

@wendt88 I figured out the issue. If you uses setOnMapClickListener or setOnMapLongClickListener function you need to return a boolean. The new Mapbox Native SDK allows for multiple listeners on an event and follows the standard pattern of returning 'true' when a handler has handled the event and others shouldn't. Not returning a boolean from the listener function will cause a crash. https://docs.mapbox.com/android/api/map-sdk/9.2.0/index.html

EX:
mapbox.setOnMapClickListener((point: LatLng) => { console.log("Map clicked at latitude: " + point.lat + ", longitude: " + point.lng); // do stuff ... return true });

@Yermo
Copy link
Owner

Yermo commented Jul 8, 2020

@TPham92 good find.

@wendt88
Copy link
Author

wendt88 commented Jul 9, 2020

@TPham92 thx for your feedback! now i found out, that the app crashs on every map (not marker) tap.
I do not have any listener. debugging a bit I found that on tap it gets called checkForCircleClickEvent as default witch returns false and the app crashs.

@Yermo could you fix this (return true) ASAP please?

@wendt88 wendt88 changed the title tap on marker can cause an app crash on android tap on map cause an app crash on android Jul 9, 2020
@ignacio68
Copy link

ignacio68 commented Oct 23, 2020

@wendt88 I figured out the issue. If you uses setOnMapClickListener or setOnMapLongClickListener function you need to return a boolean. The new Mapbox Native SDK allows for multiple listeners on an event and follows the standard pattern of returning 'true' when a handler has handled the event and others shouldn't. Not returning a boolean from the listener function will cause a crash. https://docs.mapbox.com/android/api/map-sdk/9.2.0/index.html

EX:
mapbox.setOnMapClickListener((point: LatLng) => { console.log("Map clicked at latitude: " + point.lat + ", longitude: " + point.lng); // do stuff ... return true });

Thank you, It's work very fine in my Nativescript-Vue application.
In Vue you need to make a little change in the code, remove the function arrow:

mapbox.setOnMapClickListener(function(point: LatLng) {
    console.log("Map clicked at latitude: " + point.lat + ", longitude: " + point.lng); 
    // do stuff ... 
    return true 
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants