title: How to disable a button in Kotlin?
body: <p>I have created 2 activities, well the first one I use it as splash screen, now in the second one I have difficulties when deactivating a button, I leave the code for your understanding</p>
  
  <p><strong>activity_main2.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.constraint.ConstraintLayout
          xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          xmlns:app="http://schemas.android.com/apk/res-auto"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          tools:context=".TemaCalcActivity"&gt;
  
      &lt;Spinner
              android:layout_width="144dp"
              android:layout_height="39dp"
              android:id="@+id/spnDiferencia" app:layout_constraintEnd_toEndOf="parent"
              android:layout_marginStart="8dp" app:layout_constraintStart_toEndOf="@+id/spnMP"
              android:layout_marginEnd="8dp" android:layout_marginTop="24dp"
              app:layout_constraintTop_toBottomOf="@+id/textView5"/&gt;
  
      &lt;Button
              android:text="OK"
              android:layout_width="0dp"
              android:layout_height="wrap_content"
              android:id="@+id/button" app:layout_constraintStart_toStartOf="parent" android:layout_marginStart="120dp"
              app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="120dp" android:layout_marginTop="32dp"
              app:layout_constraintTop_toBottomOf="@+id/spnMP" android:background="@drawable/button_effect"
              android:textSize="18sp" android:textStyle="bold" android:layout_marginBottom="8dp"
              app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintHorizontal_bias="0.0"
              app:layout_constraintVertical_bias="0.026" android:onClick="onBotonFinalizar" android:enabled="false"/&gt;
  
  &lt;/android.support.constraint.ConstraintLayout&gt;
  </code></pre>
  
  <p><strong>Main2Activity.kt</strong></p>
  
  <pre><code>class Main2Activity : AppCompatActivity() {
  
      override fun onCreate(savedInstanceState: Bundle?) {
  
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_main2)
  
          spnDiferencia.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
              override fun onItemSelected(parent: AdapterView&lt;*&gt;?, view: View?, position: Int, id: Long) {
                  when (position) {
                      0 -&gt; { button.isEnabled = true}
                      1 -&gt; { button.isEnabled = false}
          }
  }
  
  </code></pre>
  
  <p>The error I have is that the entire application is stopped and then restarted, making this a repetition.</p>
  
  <pre><code>button.isEnabled = true
  // or
  button.isClickable = true
  
  </code></pre>
  
  <p>caution    --->  <strong>button == btnCalcular</strong></p>
  
  <p>--- <strong><em>error log</em></strong> ---</p>
  
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: main
      Process: com.mrl.fr.tuto, PID: 22066
      java.lang.IllegalStateException: btnCalcular must not be null
          at com.mrl.fr.tuto.Main2Activity$onCreate$5.onItemSelected(Main2cActivity.kt:128)
          at android.widget.AdapterView.fireOnSelected(AdapterView.java:919)
          at android.widget.AdapterView.dispatchOnItemSelected(AdapterView.java:908)
          at android.widget.AdapterView.access$300(AdapterView.java:53)
          at android.widget.AdapterView$SelectionNotifier.run(AdapterView.java:878)
          at android.os.Handler.handleCallback(Handler.java:815)
          at android.os.Handler.dispatchMessage(Handler.java:104)
          at android.os.Looper.loop(Looper.java:194)
          at android.app.ActivityThread.main(ActivityThread.java:5631)
          at java.lang.reflect.Method.invoke(Native Method)
          at java.lang.reflect.Method.invoke(Method.java:372)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
  
  </code></pre>