question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Map breaks on android when moving to current location (Android only)

See original GitHub issue

Hi Torben,

In my app I am centring the view above the current user location when the map page appears. I do this by implementing the UserLocationChangedCommand and call MoveToRegion.

On iOS everything is working fine, unfortunately my Android version breaks when re-opening the map page. The break occurs when:

  • Don’t change first default region, change page, return to map, then change the map -> BREAK (first in video)
  • Change the map region, change page, return to map -> BREAK (second in video)

Below please find the Stack Trance, some of my code and a link to a video showing the problem. The application breaks somewhere in the background, stack trace is taken from the output window.

Stack Trace

Unhanded Exception:

System.NullReferenceException: Object reference not set to an instance of an object.

07-14 12:20:55.145 D/Mono ( 2345): DllImport attempting to load: ‘/system/lib/liblog.so’. 07-14 12:20:55.145 D/Mono ( 2345): DllImport loaded library ‘/system/lib/liblog.so’. 07-14 12:20:55.145 D/Mono ( 2345): DllImport searching in: ‘/system/lib/liblog.so’ (‘/system/lib/liblog.so’). 07-14 12:20:55.145 D/Mono ( 2345): Searching for ‘__android_log_print’. 07-14 12:20:55.145 D/Mono ( 2345): Probing ‘__android_log_print’. 07-14 12:20:55.145 D/Mono ( 2345): Found as ‘_android_log_print’. 07-14 12:20:55.149 I/MonoDroid( 2345): UNHANDLED EXCEPTION: 07-14 12:20:55.149 I/MonoDroid( 2345): System.NullReferenceException: Object reference not set to an instance of an object. 07-14 12:20:55.149 I/MonoDroid( 2345): at TK.CustomMap.Droid.TKCustomMapRenderer.MoveToCenter () [0x0000f] in <filename unknown>:0 07-14 12:20:55.149 I/MonoDroid( 2345): at TK.CustomMap.Droid.TKCustomMapRenderer.FormsMapPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs e) [0x0005d] in <filename unknown>:0 07-14 12:20:55.149 I/MonoDroid( 2345): at (wrapper delegate-invoke) <Module>:invoke_void_object_PropertyChangedEventArgs (object,System.ComponentModel.PropertyChangedEventArgs) 07-14 12:20:55.149 I/MonoDroid( 2345): at Xamarin.Forms.BindableObject.OnPropertyChanged (System.String propertyName) [0x0000a] in C:\BuildAgent3\work\aad494dc9bc9783\Xamarin.Forms.Core\BindableObject.cs:137 07-14 12:20:55.149 I/MonoDroid( 2345): at Xamarin.Forms.Element.OnPropertyChanged (System.String propertyName) [0x00000] in C:\BuildAgent3\work\aad494dc9bc9783\Xamarin.Forms.Core\Element.cs:362 07-14 12:20:55.149 I/MonoDroid( 2345): at TK.CustomMap.TKCustomMap.OnPropertyChanged (System.String propertyName) [0x00000] in <filename unknown>:0 07-14 12:20:55.149 I/MonoDroid( 2345): at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindablePropertyContext context, System.Object value, Boolean currentlyApplying, SetValueFlags attributes, Boolean silent) [0x000f4] in C:\BuildAgent3\work\aad494dc9bc9783\Xamarin.Forms.Core\BindableObject.cs:581 07-14 12:20:55.149 I/MonoDroid( 2345): at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes) [0x0014b] in C:\BuildAgent3\work\aad494dc9bc9783\Xamarin.Forms.Core\BindableObject.cs:378 07-14 12:20:55.149 I/MonoDroid( 2345): at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value, Boolean fromStyle, Boolean checkAccess) [0x0005f] in C:\BuildAgent3\work\aad494dc9bc9783\Xamarin.Forms.Core\BindableObject.cs:531 07-14 12:20:55.149 I/MonoDroid( 2345): at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value) [0x00000] in C:\BuildAgent3\work\aad494dc9bc9783\Xamarin.Forms.Core\BindableObject.cs:83 07-14 12:20:55.149 I/MonoDroid( 2345): at TK.CustomMap.TKCustomMap.set_MapCenter (Position value) [0x00000] in <filename unknown>:0 07-14 12:20:55.149 I/MonoDroid( 2345): at TK.CustomMap.Droid.TKCustomMapRenderer.OnCameraChange (System.Object sender, Android.Gms.Maps.CameraChangeEventArgs e) [0x0001f] in <filename unknown>:0 07-14 12:20:55.149 I/MonoDroid( 2345): at Android.Gms.Maps.GoogleMap+IOnCameraChangeListenerImplementor.OnCameraChange (Android.Gms.Maps.Model.CameraPosition position) [0x0001a] in <filename unknown>:0 07-14 12:20:55.149 I/MonoDroid( 2345): at Android.Gms.Maps.GoogleMap+IOnCameraChangeListenerInvoker.n_OnCameraChange_Lcom_google_android_gms_maps_model_CameraPosition (IntPtr jnienv, IntPtr native__this, IntPtr native_position) [0x00011] in <filename unknown>:0 07-14 12:20:55.149 I/MonoDroid( 2345): at (wrapper dynamic-method) System.Object:02c591bd-9913-41ba-9f4a-89ccdc181512 (intptr,intptr,intptr) 07-14 12:20:55.153 D/Mono ( 2345): DllImport searching in: ‘__Internal’ (’(null)'). 07-14 12:20:55.153 D/Mono ( 2345): Searching for ‘java_interop_jnienv_throw’. 07-14 12:20:55.153 D/Mono ( 2345): Probing ‘java_interop_jnienv_throw’. 07-14 12:20:55.153 D/Mono ( 2345): Found as ‘java_interop_jnienv_throw’. An unhandled exception occurred

In mgmain JNI_OnLoad 07-14 12:20:55.709 E/mono ( 2345): 07-14 12:20:55.709 E/mono ( 2345): Unhanded Exception:. 07-14 12:20:55.709 E/mono ( 2345): System.NullReferenceException: Object reference not set to an instance of an object. 07-14 12:20:55.709 E/mono ( 2345): at (wrapper dynamic-method) System.Object:02c591bd-9913-41ba-9f4a-89ccdc181512 (intptr,intptr,intptr) 07-14 12:20:55.709 E/mono ( 2345): at (wrapper native-to-managed) System.Object:02c591bd-9913-41ba-9f4a-89ccdc181512 (intptr,intptr,intptr) 07-14 12:20:55.709 E/mono-rt ( 2345): [ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object. 07-14 12:20:55.709 E/mono-rt ( 2345): at (wrapper dynamic-method) System.Object:02c591bd-9913-41ba-9f4a-89ccdc181512 (intptr,intptr,intptr) 07-14 12:20:55.709 E/mono-rt ( 2345): at (wrapper native-to-managed) System.Object:02c591bd-9913-41ba-9f4a-89ccdc181512 (intptr,intptr,intptr)

Code

TKCustomMap map = new TKCustomMap()
{
    IsShowingUser = true,
    MapType = MapType.Street,
    IsRegionChangeAnimated = true,
    VerticalOptions = LayoutOptions.FillAndExpand,
    HorizontalOptions = LayoutOptions.FillAndExpand
};

map.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(ConfigAccess.DefaultLatitude, ConfigAccess.DefaultLongitude), Distance.FromMeters(ConfigAccess.DefaultDistance)));

map.SetBinding(TKCustomMap.CustomPinsProperty, "Pins");
map.SetBinding(TKCustomMap.SelectedPinProperty, "SelectedPin");
map.SetBinding(TKCustomMap.MapRegionProperty, "MapRegion");
map.SetBinding(TKCustomMap.MapCenterProperty, "MapCenter");
map.SetBinding(TKCustomMap.CalloutClickedCommandProperty, "CalloutClickedCommand");

map.UserLocationChangedCommand = new Command<Position>(p =>
{
    if (!_viewIsAppearing) return;

    map.MoveToRegion(MapSpan.FromCenterAndRadius(p, Distance.FromMeters(ConfigAccess.DefaultDistance)));
    _viewIsAppearing = false;
});

Link to video

Video showcasing the issue

Please let me know if you need any more information from me.

Thanks and kind regards, Nikolai

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
TorbenKcommented, Aug 24, 2016

Unfortunately not, I’m sorry. I just dont have enough time. I have a lot of projects currently and became a father recently. I’ll try to find some time…

0reactions
Bobisbackcommented, Apr 24, 2017

Guys check out this issue they may be related: https://github.com/TorbenK/TK.CustomMap/issues/214

It looks like formsmap is null in some onproperty changed events. this might be the same case in your function as well.

P.S if you guys wanna test some more drop the pdb files into your references and put a breakpoints in that function to find out what is null. Attached are the files if you wanna just drop them into your nuget lib folder for tkcustom maps. Just keep in mind i used version 1.5.2 pre1.

Debug.zip

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fix Maps when it crashes - Android
On your Android phone or tablet, open the Settings app . Tap Apps & notifications. Follow the steps on your device to find...
Read more >
How to Fix Google Maps When It's Not Working on Android
1. Enable Location Accuracy · 2. Disable Wi-Fi Only Mode · 3. Check Your Internet Connection · 4. Calibrate Google Maps · 5....
Read more >
Continuously update marker when location changed on ...
Initially I developed a code for marking two Geo points on map and showing route between them. Now I am trying to move...
Read more >
7 Quick Fixes for Google Maps Location Sharing Not ...
If there is too much cache in your Google Maps, google location sharing will not update. Here are the steps to clear the...
Read more >
Select Current Place and Show Details on a Map
Learn how to find find the current location of an Android device and display details of the place (a business or other point...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found