title: Android kotlin.TypeCastException: null cannot be cast to non-null type com.google.android.gms.maps.SupportMapFragment
body: <p>I'm trying to code my current app in Kotlin, but I get null cannot be casted to non-null type. I've tried a lot of different stuff, but I keep getting the same problem. Not sure what to do. Any help would be appreciated!</p>
  
  <p>Code:</p>
  
  <pre><code>class MapsActivity : AppCompatActivity(), OnMapReadyCallback {
  
  private lateinit var mMap: GoogleMap
  private lateinit var button: Button
  
  override fun onCreate(savedInstanceState: Bundle?) {
      super.onCreate(savedInstanceState)
      setContentView(R.layout.activity_maps)
  
      val mapFragment = supportFragmentManager
              .findFragmentById(R.id.mapFragment) as SupportMapFragment
      mapFragment.getMapAsync(this)
  }
  
  override fun onMapReady(googleMap: GoogleMap) {
      mMap = googleMap;
      setUpMap();
  }
  
  fun setUpMap() {
  
      val et = findViewById&lt;EditText&gt;(R.id.editText);
      val et2 = findViewById&lt;EditText&gt;(R.id.editText2);
      val lat = et.getText().toString().toDouble();
      val lng = et2.getText().toString().toDouble();
      //val ll = LatLng(lat, lng)
  
      button = findViewById(R.id.button) as Button
      button.setOnClickListener {
          goToLocation(lat, lng, 11.0f);
      }
  }
  
  fun goToLocation(lat:Double, lng:Double, zoom:Float) {
      val ll = LatLng(lat, lng);
      val update = CameraUpdateFactory.newLatLngZoom(ll, zoom);
      mMap.addMarker(MarkerOptions().position(ll).title("Marquette, Michigan"))
      mMap.moveCamera(update);
  }
  </code></pre>
  
  <p>XML:</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical"
  android:paddingBottom="16dp"
  android:paddingLeft="16dp"
  android:paddingRight="16dp"
  android:paddingTop="16dp"
  tools:layout="@layout/activity_maps"&gt;
  
  &lt;EditText
      android:id="@+id/editText"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:ems="10"
      android:inputType="textPersonName" /&gt;
  
  &lt;EditText
      android:id="@+id/editText2"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:ems="10"
      android:inputType="textPersonName" /&gt;
  
  &lt;Button
      android:id="@+id/button"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:text="Submit"/&gt;
      &lt;!-- android:onClick="locate"/&gt; --&gt;
  
  &lt;fragment
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:name="com.google.android.gms.maps.SupportMapFragment"
      android:id="@+id/mapFragment"
      /&gt;
  </code></pre>
  
  <p></p>
  
  <p>Logs:</p>
  
  <blockquote>
    <p>Caused by: kotlin.TypeCastException: null cannot be cast to non-null type com.google.android.gms.maps.SupportMapFragment
            at com.example.nrice.mapsproject.MapsActivity.onCreate(MapsActivity.kt:38)</p>
  </blockquote>