title: Android App in Kotlin not inflating Fragment Layout properly
body: <p>I have a Problem.</p>
  
  <p>I wrote a Java Android App and converted to Kotlin. It worked in Java jsut fine but now when I run the app it gives me a RuntimeError. The Fragment cant be inflated:</p>
  
  <p><strong>Errors</strong></p>
  
  <pre><code>FATAL EXCEPTION: main
  Process: com.jaielsoft.www.emergencyapp, PID: 10753
      java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jaielsoft.www.emergencyapp/de.htw_berlin.f4.ai.aa.activities.MainActivity}: android.view.InflateException: Binary XML file line #0: Error inflating class fragment
      ...
  Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class fragment
      ....
  Caused by: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter savedInstanceState    
      ....
  </code></pre>
  
  <p>Here are the involved classes and layout files:</p>
  
  <p><strong>MainActivity.kt:</strong></p>
  
  <pre><code>package de.htw_berlin.f4.ai.aa.activities
  
  ...
  
  class MainActivity : FragmentActivity() {
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          if (savedInstanceState == null)
              this.setContentView(R.layout.mainlayout)
      }
  }
  </code></pre>
  
  <p><strong>mainlayout.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"&gt;
  
  &lt;fragment
      android:name="de.htw_berlin.f4.ai.aa.fragments.MainFragment"
      android:id="@+id/main_menu_fragment"
      android:layout_width="match_parent"
      android:layout_height="match_parent" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p><strong>MainFragment.kt</strong></p>
  
  <pre><code>package de.htw_berlin.f4.ai.aa.fragments
  
  ...
  
  class MainFragment : Fragment() {
          override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle): View? {
          return inflater.inflate(R.layout.mainfragmentlayout, container, false)
      }
  
  }
  </code></pre>
  
  <p><strong>mainfragmentlayout.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent" android:layout_height="match_parent"&gt;
  
      &lt;ImageView
          android:id="@+id/imageView"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_alignParentStart="true"
          android:layout_alignParentTop="true"
          android:scaleType="centerCrop"
          android:src="@drawable/blue"
          android:contentDescription="@null" /&gt;
  
      &lt;ImageButton
          android:id="@+id/sosButton"
          android:layout_width="300dp"
          android:layout_height="300dp"
          android:layout_above="@+id/contactsButton"
          android:layout_alignStart="@+id/contactsButton"
          android:onClick="callForHelp"
          android:layout_marginBottom="98dp"
          android:background="@null"
          android:scaleType="centerCrop"
          android:src="@drawable/emergencybutton"
          android:contentDescription="@null"/&gt;
  
      &lt;ImageButton
          android:id="@+id/contactsButton"
          android:layout_width="300dp"
          android:layout_height="100dp"
          android:layout_alignParentBottom="true"
          android:layout_centerHorizontal="true"
          android:layout_marginBottom="57dp"
          android:background="@null"
          android:onClick="startContactActivity"
          android:scaleType="centerCrop"
          android:src="@drawable/contactsbutton"
          android:contentDescription="@null" /&gt;
  
  &lt;ImageButton
          android:id="@+id/mapButton"
          android:layout_width="150dp"
          android:layout_height="50dp"
          android:layout_alignParentEnd="true"
          android:layout_alignParentTop="true"
          android:layout_marginEnd="23dp"
          android:layout_marginTop="20dp"
          android:onClick="startMapActivity"
          android:background="@null"
          android:scaleType="centerCrop"
          android:src="@drawable/mapbutton"
          android:contentDescription="@null"/&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Where is the Problem? Can you please help me?</p>
  
  <p>Thanks in advance</p>