System Argument Null Exception when navigating away from google maps page.

JoeHonourJoeHonour GBMember
edited February 2016 in Xamarin.Android

Hey,

so i'm having an issue when implementing google maps in my Android application. I have successfully implemented the map so it displays with a correct marker. However, when I go to either go back in the app to a previous fragment displayed, or when i click on the map and go to navigate to the location (which opens google maps native app) i get an exception of type "System.ArgumentNullException". With the message "Value cannot be null, Parameter name: key." I will place my stack trace below, but does anyone know what might be causing this and what a possible fix could be?

Stack Trace:
System.ArgumentNullException: Value cannot be null.
Parameter name: key
at System.ThrowHelper.ThrowArgumentNullException (ExceptionArgument argument) [0x00000] in /Users/builder/data/lanes/2098/3efa14c4/source/mono/external/referencesource/mscorlib/system/throwhelper.cs:82
at System.Collections.Generic.Dictionary2[TKey,TValue].FindEntry (System.Collections.Generic.TKey key) [0x0000b] in /Users/builder/data/lanes/2098/3efa14c4/source/mono/external/referencesource/mscorlib/system/collections/generic/dictionary.cs:292 at System.Collections.Generic.Dictionary2[TKey,TValue].TryGetValue (System.Collections.Generic.TKey key, System.Collections.Generic.TValue& value) [0x00000] in /Users/builder/data/lanes/2098/3efa14c4/source/mono/external/referencesource/mscorlib/system/collections/generic/dictionary.cs:477
at Cirrious.MvvmCross.Droid.Support.AppCompat.MvxCachingFragmentCompatActivity.GetFragmentInfoByTag (System.String tag) [0x00001] in :0
at Cirrious.MvvmCross.Droid.Support.AppCompat.MvxCachingFragmentCompatActivity.b__20_1 (Android.Support.V4.App.Fragment frag) [0x00007] in :0
at System.Linq.Enumerable+WhereSelectEnumerableIterator2[TSource,TResult].MoveNext () [0x00064] in /Users/builder/data/lanes/2098/3efa14c4/source/mono/external/referencesource/System.Core/System/Linq/Enumerable.cs:285 at System.Collections.Generic.List1[T]..ctor (IEnumerable1 collection) [0x0008b] in /Users/builder/data/lanes/2098/3efa14c4/source/mono/external/referencesource/mscorlib/system/collections/generic/list.cs:105 at System.Linq.Enumerable.ToList[TSource] (IEnumerable1 source) [0x00011] in /Users/builder/data/lanes/2098/3efa14c4/source/mono/external/referencesource/System.Core/System/Linq/Enumerable.cs:835
at Cirrious.MvvmCross.Droid.Support.AppCompat.MvxCachingFragmentCompatActivity.GetCurrentFragmentsInfo () [0x00041] in :0
at Cirrious.MvvmCross.Droid.Support.AppCompat.MvxCachingFragmentCompatActivity.CreateFragmentTypesDictionary (Android.OS.Bundle outState) [0x0001e] in :0
at Cirrious.MvvmCross.Droid.Support.AppCompat.MvxCachingFragmentCompatActivity.OnSaveInstanceState (Android.OS.Bundle outState) [0x00025] in :0
at Android.App.Activity.n_OnSaveInstanceState_Landroid_os_Bundle_ (IntPtr jnienv, IntPtr native__this, IntPtr native_outState) [0x00011] in /Users/builder/data/lanes/2098/3efa14c4/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Android.App.Activity.cs:4442
at at (wrapper dynamic-method) System.Object:c7bc9d68-2973-4331-94bd-062e3e1c85b4 (intptr,intptr,intptr)

My XAML code:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:local="http://schemas.android.com/apk/res-auto" android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" class="com.google.android.gms.maps.SupportMapFragment"> <android.support.design.widget.AppBarLayout android:id="@+id/appbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" local:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> </android.support.design.widget.AppBarLayout> </LinearLayout>

My Fragment Code:
`public class FindUsFragment : BaseFragment, IOnMapReadyCallback
{
///


/// Tanfields location.
///

private static LatLng TANFIELDLOCATION = new LatLng (54.909732, -1.678019);

    /// <summary>
    /// How the layout is assigned to the fragment.
    /// </summary>
    /// <value>The fragment identifier.</value>
    protected override int FragmentId 
    {
        get 
        {
            return Resource.Layout.fragment_findus;
        }
    }

    /// <Docs>Called when the fragment is visible to the user and actively running.</Docs>
    /// <summary>
    /// Raises the resume event. Used to generate the request to google maps on each navigation to the page. 
    /// </summary>
    public override void OnResume ()
    {
        base.OnResume ();
        var _myMapFragment = SupportMapFragment.NewInstance (); 
        Android.Support.V4.App.FragmentTransaction tx = FragmentManager.BeginTransaction (); 
        tx.Add (Resource.Id.map, _myMapFragment); 
        tx.Commit (); 
        _myMapFragment.GetMapAsync (this); 
    }

    /// <summary>
    /// Raises the map ready event.
    /// </summary>
    /// <param name="googleMap">Google map.</param>
    public void OnMapReady (GoogleMap googleMap)
    {
        googleMap.MapType = GoogleMap.MapTypeNormal; 
        googleMap.MoveCamera (CameraUpdateFactory.NewLatLngZoom(TANFIELDLOCATION, 10.0f)); 
        googleMap.AddMarker(new MarkerOptions().SetPosition(TANFIELDLOCATION)
            .Draggable(true)
            .SetTitle("Tanfield Railway")
            .SetSnippet("The location of Tanfield Railway")
        );
    }
}

`

Any help would be appreciated,

Cheers.
Joe.

Sign In or Register to comment.