title: How to fix Parameter specified as non-null is null on rotating screen in a Fragment while creating a Spinner in Kotlin?
body: <p>Hello everyone in my fragment, i have added a spinner in my fragment and little bit of code to calculate moles but when i rotate screen it crashes and throw an error by i don't know why it crashes , When try to check for Non-null object i don't What that is the cause of error , Here is the error :</p>
  
  <pre><code>java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull
  </code></pre>
  
  <p>Here is my first fragment file :</p>
  
  <pre><code>private var mListener: OnFragmentInteractionListener? = null
  
  
  override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
      // Inflate the layout for this fragment
      return inflater!!.inflate(R.layout.fragment_first, container, false)
  }
  
  override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
      super.onViewCreated(view, savedInstanceState)
      //activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
      /*Find the id of spinner*/
      val spinner = lol
  
      /*set an adapter with strings array*/
      spinner.adapter = ArrayAdapter(activity, R.layout.support_simple_spinner_dropdown_item, resources.getStringArray(R.array.atoms)) as SpinnerAdapter
  
      /*set click listener*/
      spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
          override fun onItemSelected(parent: AdapterView&lt;*&gt;, view: View, position: Int, id: Long) {
              val num = when (spinner.selectedItem.toString()) {
                  "H" -&gt; editText.setText("1")
                  "He" -&gt; editText.setText("4")
                  "C" -&gt; editText.setText("12")
                  "O" -&gt; editText.setText("16")
                  else -&gt; editText.setText("")
              }
          }
  
          override fun onNothingSelected(parent: AdapterView&lt;*&gt;) {
              /*Do something if nothing selected*/
          }
  
  
  
      }
  
      button.setOnClickListener {
          if (
          editText2.text.toString().length &gt; 0 &amp;&amp;
                  editText.text.toString().length &gt; 0) {
              val num2 = editText.text.toString().toDouble()
              val num1 = editText2.text.toString().toDouble()
              val num = num1/num2
              textView.setText("$num moles")
          }
          else {
              textView.setText("Please Enter a correct value")
          }
      }
  }
  </code></pre>
  
  <p>Here is my fragment_first.xml file :</p>
  
  <pre><code>&lt;android.support.constraint.ConstraintLayout
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"&gt;
  
      &lt;TextView
          android:id="@+id/textView"
          android:layout_width="294dp"
          android:layout_height="80dp"
          android:layout_weight="1"
          android:text="Amswer : No of Moles"
          android:textAlignment="center"
          android:textSize="20sp"
          app:layout_anchorGravity="right|top"
          app:layout_constraintBottom_toBottomOf="parent"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toTopOf="parent"
          app:layout_constraintVertical_bias="0.556" /&gt;
  
      &lt;TextView
          android:id="@+id/textView1"
          android:layout_width="143dp"
          android:layout_height="46dp"
          android:layout_weight="1"
          android:text="Amount in Grams "
          android:textAlignment="center"
          android:textSize="20sp"
          app:layout_anchorGravity="left|bottom"
          app:layout_constraintBottom_toBottomOf="parent"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintHorizontal_bias="0.066"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toTopOf="parent"
          app:layout_constraintVertical_bias="0.305" /&gt;
  
      &lt;Spinner
          android:id="@+id/lol"
          android:layout_width="145dp"
          android:layout_height="57dp"
  
          app:layout_anchorGravity="left|top"
          app:layout_constraintBottom_toBottomOf="parent"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintHorizontal_bias="0.07"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toTopOf="parent"
          app:layout_constraintVertical_bias="0.136" /&gt;
  
      &lt;Button
          android:id="@+id/button"
          android:layout_width="138dp"
          android:layout_height="43dp"
          android:text="Calculate"
          app:layout_constraintBottom_toBottomOf="parent"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toTopOf="parent"
          app:layout_constraintVertical_bias="0.788" /&gt;
  
      &lt;EditText
          android:id="@+id/editText"
          android:layout_width="148dp"
          android:layout_height="57dp"
          android:ems="10"
          android:hint="Gram"
          android:inputType="numberDecimal|number"
          app:layout_anchorGravity="bottom|center"
          app:layout_constraintBottom_toBottomOf="parent"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintHorizontal_bias="0.762"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toTopOf="parent"
          app:layout_constraintVertical_bias="0.137" /&gt;
  
      &lt;EditText
          android:id="@+id/editText2"
          android:layout_width="148dp"
          android:layout_height="57dp"
          android:ems="10"
          android:hint="Gram"
          android:inputType="numberDecimal|number"
          app:layout_anchorGravity="center_horizontal|center"
          app:layout_constraintBottom_toBottomOf="parent"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintHorizontal_bias="0.716"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toTopOf="parent"
          app:layout_constraintVertical_bias="0.288" /&gt;
  
  &lt;/android.support.constraint.ConstraintLayout&gt;
  </code></pre>