Forum Xamarin.Forms

new Geocoder()).GetPositionsForAddressAsync error for android

wc.5543wc.5543 USUniversity ✭✭

I got this error, I don't know how to fix

[MonoDroid] UNHANDLED EXCEPTION: Java.Lang.NullPointerException: Exception of type 'Java.Lang.NullPointerException' was thrown.
[MonoDroid] at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (IntPtr jobject, IntPtr jclass, IntPtr jmethod, Android.Runtime.JValue[] parms) [0x00000] in :0
[MonoDroid] at Android.Runtime.JNIEnv.FinishCreateInstance (IntPtr instance, IntPtr jclass, IntPtr constructorId, Android.Runtime.JValue[] constructorParameters) [0x00000] in :0
[MonoDroid] at Android.Locations.Geocoder..ctor (Android.Content.Context context) [0x00000] in :0
[MonoDroid] at Xamarin.Forms.Maps.Android.GeocoderBackend+d__2.MoveNext () [0x00000] in :0
[MonoDroid] --- End of stack trace from previous location where exception was thrown ---
[MonoDroid] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in :0
[MonoDroid] at System.Runtime.CompilerServices.TaskAwaiter1[System.Collections.Generic.IEnumerable1[Xamarin.Forms.Maps.Position]].GetResult () [0x00000] in :0
[MonoDroid] at DAI.POC.DealerMap+c__async0.MoveNext () [0x00000] in :0
[MonoDroid] --- End of managed exception stack trace ---
[MonoDroid] java.lang.NullPointerException
[MonoDroid] at android.location.GeocoderParams.(GeocoderParams.java:50)
[MonoDroid] at android.location.Geocoder.(Geocoder.java:83)
[MonoDroid] at android.location.Geocoder.(Geocoder.java:95)
[MonoDroid] at dai.poc.android.MainActivity.n_onCreate(Native Method)
[MonoDroid] at dai.poc.android.MainActivity.onCreate(MainActivity.java:28)
[MonoDroid] at android.app.Activity.performCreate(Activity.java:5231)
[MonoDroid] at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
[MonoDroid] at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
[MonoDroid] at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
[MonoDroid] at android.app.ActivityThread.access$800(ActivityThread.java:135)
[MonoDroid] at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
[MonoDroid] at android.os.Handler.dispatchMessage(Handler.java:102)
[MonoDroid] at android.os.Looper.loop(Looper.java:136)
[MonoDroid] at android.app.ActivityThread.main(ActivityThread.java:5001)
[MonoDroid] at java.lang.reflect.Method.invokeNative(Native Method)
[MonoDroid] at java.lang.reflect.Method.invoke(Method.java:515)
[MonoDroid] at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
[MonoDroid] at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
[MonoDroid] at dalvik.system.NativeStart.main(Native Method)
[mono]
[mono] Unhandled Exception:
[mono] Java.Lang.NullPointerException: Exception of type 'Java.Lang.NullPointerException' was thrown.
[mono] at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (IntPtr jobject, IntPtr jclass, IntPtr jmethod, Android.Runtime.JValue[] parms) [0x00000] in :0
[mono] at Android.Runtime.JNIEnv.FinishCreateInstance (IntPtr instance, IntPtr jclass, IntPtr constructorId, Android.Runtime.JValue[] constructorParameters) [0x00000] in :0
[mono] at Android.Locations.Geocoder..ctor (Android.Content.Context context) [0x00000] in :0
[mono] at Xamarin.Forms.Maps.Android.GeocoderBackend+d__2.MoveNext () [0x00000] in :0
[mono] --- End of stack trace from previous location where exception was thrown ---
[mono] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in :0
[mono] at System.Runtime.CompilerServices.TaskAwaiter1[System.Collections.Generic.IEnumerable1[Xamarin.Forms.Maps.Position]].GetResult ()
[mono-rt] [ERROR] FATAL UNHANDLED EXCEPTION: Java.Lang.NullPointerException: Exception of type 'Java.Lang.NullPointerException' was thrown.
[mono-rt] at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (IntPtr jobject, IntPtr jclass, IntPtr jmethod, Android.Runtime.JValue[] parms) [0x00000] in :0
[mono-rt] at Android.Runtime.JNIEnv.FinishCreateInstance (IntPtr instance, IntPtr jclass, IntPtr constructorId, Android.Runtime.JValue[] constructorParameters) [0x00000] in :0
[mono-rt] at Android.Locations.Geocoder..ctor (Android.Content.Context context) [0x00000] in :0
[mono-rt] at Xamarin.Forms.Maps.Android.GeocoderBackend+d__2.MoveNext () [0x00000] in :0
[mono-rt] --- End of stack trace from previous location where exception was thrown ---
[mono-rt] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in :0
[mono-rt] at System.Runtime.CompilerServices.TaskAwaiter1[System.Collections.Generic.IEnumerable1[Xamarin.Forms.Maps.Position]]

any suggestions?

Best Answer

Answers

  • rmarinhormarinho PTMember, Insider, Beta Xamurai

    make sure in android manifest you have set that you are using location:
    Location Permissions
    A location-aware application needs access a device's hardware sensors in order to receive GPS, Wi-Fi, and cellular data. Access is controlled through appropriate permissions in the application's Android Manifest. There are two permissions available - depending on your application's requirements and your choice of API, you will want to allow one:

    ACCESS_FINE_LOCATION – Allows an application access to GPS. Required for the GPS Provider and Passive Provider options (Passive Provider needs permission to access GPS data collected by another application or Service). Optional permission for the Network Provider.
    ACCESS_COARSE_LOCATION – Allows an application access to Cellular and Wi-Fi location. Required for Network Provider if ACCESS_FINE_LOCATION is not set.

    my other suggestion if that doesn't work maybe trying this open source by the community:

    it's ported fro Xamarin.Mobile, and it's working on all platforms:

    https://github.com/XForms/Xamarin-Forms-Labs/wiki/Geolocator

  • kaolickkaolick DEMember ✭✭

    @CraigDunn‌ Unfortunately your suggestions were not helpful. This issue is still not fixed. My Android app freezes when using the Geocoder with a slow internet connection like 2G or Edge. Works fine with WIFI. There's also a bug report since JULY (!) on bugzilla.

Sign In or Register to comment.