title: How to solve "An unhandled exception occured" with a Google Maps Android App? -Xamarin
body: <p>I made an app that runs google maps and then takes your input to find the desired place. Every time I run it through the emulator though it pops up with the message "An unhandled exception occurred". I don't know how to over come this and if this is a problem with the emulator or something wrong with my code? </p>
  
  <p>This is my Main Activity:</p>
  
  <pre><code>using Android.App;
  using Android.Widget;
  using Android.OS;
  using Android.Gms.Maps;
  using Android.Views;
  using Android.Gms.Maps.Model;
  using System.Collections.Generic;
  using Android.Locations;
  using System.Linq;
  using Android.Util;
  using System.Threading.Tasks;
  
  namespace SafeandSound
  {
  [Activity(Label = "SafeandSound", MainLauncher = true, Icon = "@drawable/icon")]
  public class MainActivity : Activity
  {
      private GoogleMap mMap;
  
      protected override void OnCreate(Bundle bundle)
      {
          base.OnCreate(bundle);
  
  
          // Set our view from the "main" layout resource
          SetContentView(Resource.Layout.Main);
  
          SetUpMap();
      }
      private void SetUpMap()
      {
          if (mMap == null)
          {
              FragmentManager.FindFragmentById&lt;MapFragment&gt;(Resource.Id.map);
          }
      }
  
      public void OnMapReady(GoogleMap googleMap)
      {
          mMap = googleMap;
  
      }
      // Button to Search for Address//
      public async System.Threading.Tasks.Task onMapSearchAsync(View view)
      {
          EditText gotAddress = (EditText)FindViewById(Resource.Id.searchText);
          string addressnew = gotAddress.Text;
          if (!Geocoder.IsPresent)
          {
              Log.Error("SO", "Geocoder is not present");
          }
          else
          {
              var geocoder = new Geocoder(this);
              var retry = 0;
              do
              {
                  var addressList = await geocoder.GetFromLocationNameAsync(addressnew, 5);
                  if (addressList.Count &gt; 0)
                  {
                      foreach (var address in addressList)
                      {
                          Log.Debug("SO", $"{address.Latitude}:{address.Longitude} - {address.FeatureName} : {address.GetAddressLine(0)} : {address.GetAddressLine(1)}");
                          LatLng latLng = new LatLng(address.Latitude, address.Longitude);
                          CameraPosition.Builder builder = CameraPosition.InvokeBuilder();
                          builder.Target(latLng);
                          builder.Zoom(10);
                          CameraPosition cameraPosition = builder.Build();
                          CameraUpdate cameraUpdate = CameraUpdateFactory.NewCameraPosition(cameraPosition);
  
                      }
                      break;
                  }
                  retry++;
                  Log.Warn("SO", $"No addresses returned...., retrying in {retry * 2} secs");
                  await Task.Delay(retry * 1000);
              } while (retry &lt; 5);
          }
  
      }
  }
  }
  </code></pre>
  
  <p>And this is my Main code:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:background="@android:color/background_light"&gt;
  &lt;LinearLayout
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:orientation="horizontal"&gt;
      &lt;EditText
          android:id="@+id/searchText"
          android:layout_width="303.5dp"
          android:layout_height="wrap_content"
          android:layout_weight="4"
          android:hint="Search Location..."
          android:textColor="#000000" /&gt;
      &lt;Button
          android:id="@+id/search_button"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_weight="0.5"
          android:onClick="onMapSearch"
          android:text="Search" /&gt;
  &lt;/LinearLayout&gt;
  &lt;fragment
      android:id="@+id/map"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:name="com.google.android.gms.maps.MapFragment"/&gt;
   &lt;/LinearLayout&gt;
  </code></pre>