Bug 36672 - NullPointerException thrown when displaying custom map
Summary: NullPointerException thrown when displaying custom map
Status: RESOLVED UPSTREAM
Alias: None
Product: Android
Classification: Xamarin
Component: Bindings ()
Version: unspecified
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2015-12-07 12:46 UTC by Paul Johnson
Modified: 2015-12-07 22:32 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED UPSTREAM

Description Paul Johnson 2015-12-07 12:46:41 UTC
I have Xam.Forms app that has a custom map renderer (it just adds a custom pin instead of a pin). I've used the code a few times in the past.

I've come to run this on my S3 and S4 Mini and get the following when I add the markers

[MonoDroid] UNHANDLED EXCEPTION:
[MonoDroid] Java.Lang.NullPointerException: Exception of type 'Java.Lang.NullPointerException' was thrown.
[MonoDroid]   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/2098/3efa14c4/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 
[MonoDroid]   at Android.Runtime.JNIEnv.CallObjectMethod (IntPtr jobject, IntPtr jmethod, Android.Runtime.JValue* parms) [0x00064] in /Users/builder/data/lanes/2098/3efa14c4/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:195 
[MonoDroid]   at Android.Gms.Maps.GoogleMap.AddMarker (Android.Gms.Maps.Model.MarkerOptions options) [0x0004a] in <filename unknown>:0 
[MonoDroid]   at airportapp.Droid.CustomMapRenderer.CreateMarker () [0x00083] in /Users/PFJ/Developer/MAG/mobileapp/Common.Droid/CustomRenderers/CustomMapRenderer.cs:50 
[MonoDroid]   at airportapp.Droid.CustomMapRenderer.OnElementPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs e) [0x00054] in /Users/PFJ/Developer/MAG/mobileapp/Common.Droid/CustomRenderers/CustomMapRenderer.cs:32 
[MonoDroid]   at (wrapper delegate-invoke) <Module>:invoke_void_object_PropertyChangedEventArgs (object,System.ComponentModel.PropertyChangedEventArgs)
[MonoDroid]   at Xamarin.Forms.BindableObject.OnPropertyChanged (System.String propertyName) [0x00012] in <filename unknown>:0 
[MonoDroid]   at Xamarin.Forms.Maps.Map.set_VisibleRegion (Xamarin.Forms.Maps.MapSpan value) [0x00035] in <filename unknown>:0 
[MonoDroid]   at Xamarin.Forms.Maps.Android.MapRenderer.UpdateVisibleRegion (Android.Gms.Maps.Model.LatLng pos) [0x000e4] in <filename unknown>:0 
[MonoDroid]   at Xamarin.Forms.Maps.Android.MapRenderer.OnCameraChange (Android.Gms.Maps.Model.CameraPosition pos) [0x00007] in <filename unknown>:0 
[MonoDroid]   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 
[MonoDroid]   at (wrapper dynamic-method) System.Object:7d3425fc-1cd9-4c87-9cf9-7b8dd4fb5663 (intptr,intptr,intptr)
[MonoDroid]   --- End of managed exception stack trace ---
[MonoDroid] java.lang.NullPointerException
[MonoDroid] 	at com.google.a.a.ae.a(Unknown Source)
[MonoDroid] 	at com.google.maps.api.android.lib6.d.dn.<init>(Unknown Source)
[MonoDroid] 	at com.google.maps.api.android.lib6.d.dm.a(Unknown Source)
[MonoDroid] 	at com.google.maps.api.android.lib6.d.ag.<init>(Unknown Source)
[MonoDroid] 	at com.google.maps.api.android.lib6.d.eu.a(Unknown Source)
[MonoDroid] 	at com.google.android.gms.maps.internal.j.onTransact(SourceFile:167)
[MonoDroid] 	at android.os.Binder.transact(Binder.java:347)
[MonoDroid] 	at com.google.android.gms.maps.internal.IGoogleMapDelegate$zza$zza.addMarker(Unknown Source)
[MonoDroid] 	at com.google.android.gms.maps.GoogleMap.addMarker(Unknown Source)
[MonoDroid] 	at md5d956392b2b421ac2c9ccfc063253dcd9.MapRenderer.n_onCameraChange(Native Method)
[MonoDroid] 	at md5d956392b2b421ac2c9ccfc063253dcd9.MapRenderer.onCameraChange(MapRenderer.java:54)
[MonoDroid] 	at com.google.android.gms.maps.GoogleMap$7.onCameraChange(Unknown Source)
[MonoDroid] 	at com.google.android.gms.maps.internal.zze$zza.onTransact(Unknown Source)
[MonoDroid] 	at android.os.Binder.transact(Binder.java:347)
[MonoDroid] 	at com.google.android.gms.maps.internal.aa.a(SourceFile:93)
[MonoDroid] 	at com.google.maps.api.android.lib6.gmm6.c.a.a(Unknown Source)
[MonoDroid] 	at com.google.maps.api.android.lib6.gmm6.c.b.run(Unknown Source)
[MonoDroid] 	at android.os.Handler.handleCallback(Handler.java:730)
[MonoDroid] 	at android.os.Handler.dispatchMessage(Handler.java:92)
[MonoDroid] 	at android.os.Looper.loop(Looper.java:176)
[MonoDroid] 	at android.app.ActivityThread.main(ActivityThread.java:5419)
[MonoDroid] 	at java.lang.reflect.Method.invokeNative(Native Method)
[MonoDroid] 	at java.lang.reflect.Method.invoke(Method.java:525)
[MonoDroid] 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
[MonoDroid] 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
[MonoDroid] 	at dalvik.system.NativeStart.main(Native Method)
[mono-rt] Stacktrace:
[mono-rt] 
[mono-rt]   at <unknown> <0xffffffff>
[mono-rt]   at (wrapper managed-to-native) object.wrapper_native_0x40b58211 (intptr,intptr,intptr) <IL 0x0002b, 0xffffffff>
[mono-rt]   at Android.Runtime.JNIEnv.CallObjectMethod (intptr,intptr) [0x00040] in /Users/builder/data/lanes/2098/3efa14c4/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:174
[mono-rt]   at Java.Lang.Throwable.get_Message () [0x00043] in /Users/builder/data/lanes/2098/3efa14c4/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Java.Lang.Throwable.cs:270
[mono-rt]   at (wrapper runtime-invoke) <Module>.runtime_invoke_object__this__ (object,intptr,intptr,intptr) <IL 0x00058, 0xffffffff>
[mono-rt]   at <unknown> <0xffffffff>
[mono-rt]   at (wrapper dynamic-method) object.7d3425fc-1cd9-4c87-9cf9-7b8dd4fb5663 (intptr,intptr,intptr) <IL 0x00034, 0x000a4>
[mono-rt]   at (wrapper native-to-managed) object.7d3425fc-1cd9-4c87-9cf9-7b8dd4fb5663 (intptr,intptr,intptr) <IL 0x00027, 0xffffffff>
[mono-rt] 
[mono-rt] Attempting native Android stacktrace:
[mono-rt] 
[mono-rt]   at dvmAbort+67 [0x40b5d2fc]
[mono-rt]   at ???+266813 [0x40b5823d]
[mono-rt]   at ???+45248 [0x67ce80c0]
[mono-rt] 
[mono-rt] =================================================================
[mono-rt] Got a SIGSEGV while executing native code. This usually indicates
[mono-rt] a fatal error in the mono runtime or one of the native libraries 
[mono-rt] used by your application.
[mono-rt] =================================================================
[mono-rt] 
[libc] Fatal signal 11 (SIGSEGV) at 0xdeadd00d (code=1), thread 25327 (airport.android)

Looking at the values in the map object, the only null I can see is for MyLocation (which is deprecated and all of the examples available never sets this property either)

I'm using GooglePlayServices 26 (there isn't a reference to 27 in my packages) and X.F.Maps 2.0.0.6490

=== Xamarin Studio ===

Version 5.10.1 (build 3)
Installation UUID: 728e2a5d-c6a2-4d84-a931-ee64cb78694c
Runtime:
	Mono 4.2.1 (explicit/6dd2d0d)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 402010102

=== Xamarin.Profiler ===

Version: 0.18.0.0
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Apple Developer Tools ===

Xcode 7.1.1 (9081)
Build 7B1005

=== Xamarin.iOS ===

Version: 9.2.1.54 (Business Edition)
Hash: eb4c1ef
Branch: master
Build date: 2015-12-01 02:12:30-0500

=== Xamarin.Android ===

Version: 6.0.0.34 (Business Edition)
Android SDK: /Users/PFJ/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.3    (API level 10)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
		5.1    (API level 22)
		6.0    (API level 23)

SDK Tools Version: 24.4.1
SDK Platform Tools Version: 23.0.1
SDK Build Tools Version: 23.0.2

Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

=== Xamarin Android Player ===

Version: 0.3.7
Location: /Applications/Xamarin Android Player.app

=== Xamarin.Mac ===

Version: 2.4.0.109 (Business Edition)

=== Build Information ===

Release ID: 510010003
Git revision: f2021a209d66d49cbc0649a6d968b29040e57807
Build date: 2015-12-01 10:43:40-05
Xamarin addins: dfd4f5103e8951edbc8ac24480b53b53c55e04ff
Build lane: monodevelop-lion-cycle6-baseline

=== Operating System ===

Mac OS X 10.11.2
Darwin Pauls-MacBook-Pro.local 15.2.0 Darwin Kernel Version 15.2.0
    Fri Nov 13 19:43:59 PST 2015
    root:xnu-3248.20.55~1/RELEASE_X86_64 x86_64
Comment 1 Paul Johnson 2015-12-07 12:47:38 UTC
The code for the custom renderer is this

public class CustomMapRenderer : MapRenderer, IOnMapReadyCallback
    {
        bool isDrawnDone;
        GoogleMap map;
        CustomMap formsMap;

        protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {

            base.OnElementPropertyChanged(sender, e);
            var androidMapView = (MapView)Control;
            formsMap = (CustomMap)sender;

            androidMapView.GetMapAsync(this);

            if (e.PropertyName.Equals("VisibleRegion") && !isDrawnDone && map != null)
                CreateMarker();
        }

        void CreateMarker()
        {
            var markerWithIcon = new MarkerOptions();

            var myLoc = LocationManager.GetUpdatedCoords(true);

            markerWithIcon.SetPosition(new LatLng(formsMap.MapPinLatitude, formsMap.MapPinLongitude));
            markerWithIcon.SetTitle("Your vehicle");
            markerWithIcon.SetSnippet(string.Empty);
            markerWithIcon.SetIcon(BitmapDescriptorFactory.FromAsset("pinned_location.png"));
            map.MyLocationEnabled = formsMap.IsShowingUser;
            map.SetIndoorEnabled(false);

            //try
            //{
            map.AddMarker(markerWithIcon);
            //}
/*            catch (NullPointerException ex)
            {
                Console.WriteLine("Exception : {0}--{1}", ex.Message, ex.InnerException);
            }*/
            isDrawnDone = true;
        }

        public void OnMapReady(GoogleMap googleMap)
        {
            map = googleMap;
        }

        protected override void OnLayout(bool changed, int l, int t, int r, int b)
        {
            base.OnLayout(changed, l, t, r, b);

            if (changed)
            {
                isDrawnDone = false;
            }
        }
Comment 2 Jonathan Pryor 2015-12-07 22:17:27 UTC
This is either a Google Maps bug or an API usage "bug":

>   --- End of managed exception stack trace ---
> java.lang.NullPointerException
> 	at com.google.a.a.ae.a(Unknown Source)
> 	at com.google.maps.api.android.lib6.d.dn.<init>(Unknown Source)
> 	at com.google.maps.api.android.lib6.d.dm.a(Unknown Source)
> 	at com.google.maps.api.android.lib6.d.ag.<init>(Unknown Source)
> 	at com.google.maps.api.android.lib6.d.eu.a(Unknown Source)
> 	at com.google.android.gms.maps.internal.j.onTransact(SourceFile:167)
> 	at android.os.Binder.transact(Binder.java:347)
> 	at com.google.android.gms.maps.internal.IGoogleMapDelegate$zza$zza.addMarker(Unknown Source)
> 	at com.google.android.gms.maps.GoogleMap.addMarker(Unknown Source)
> 	at md5d956392b2b421ac2c9ccfc063253dcd9.MapRenderer.n_onCameraChange(Native Method)
> 	at md5d956392b2b421ac2c9ccfc063253dcd9.MapRenderer.onCameraChange(MapRenderer.java:54)
> 	at com.google.android.gms.maps.GoogleMap$7.onCameraChange(Unknown Source)
> 	at com.google.android.gms.maps.internal.zze$zza.onTransact(Unknown Source)
> 	at android.os.Binder.transact(Binder.java:347)
> 	at com.google.android.gms.maps.internal.aa.a(SourceFile:93)
> 	at com.google.maps.api.android.lib6.gmm6.c.a.a(Unknown Source)
> 	at com.google.maps.api.android.lib6.gmm6.c.b.run(Unknown Source)
> 	at android.os.Handler.handleCallback(Handler.java:730)
> 	at android.os.Handler.dispatchMessage(Handler.java:92)
> 	at android.os.Looper.loop(Looper.java:176)
> 	at android.app.ActivityThread.main(ActivityThread.java:5419)
> 	at java.lang.reflect.Method.invokeNative(Native Method)
> 	at java.lang.reflect.Method.invoke(Method.java:525)
> 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
> 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
> 	at dalvik.system.NativeStart.main(Native Method)

Notice that the NullPointerException is raised from Java code, *deeply nested* Java code, via GoogleMap.addMarker().

As a quick guess, this looks like it could be:

https://code.google.com/p/gmaps-api-issues/issues/detail?id=7696

In that it's a call to GoogleMap.addMarker() which calls Binder.transact() which eventually throws.

The only problem is that the method names don't match, but I assume that they're using Proguard to link+rename identifiers on every build, so constantly changing type and method names may be expected.

Assuming that's the case, a suggested workaround is to use Android Resources instead of assets:

https://code.google.com/p/gmaps-api-issues/issues/detail?id=7696#c4

Though comment #15 suggests that might not actually work.

Do you know which version of Google Play Services is being used on the target device?
Comment 3 Paul Johnson 2015-12-07 22:32:21 UTC
Google Play Services is showing up as being v8.3.01 (2385995-036)