title: Why is Android Studio not populating a button id for me in Main Activity?
body: <p>I must be having a slow morning.  I started a new project to work with services.  I created a very simple layout with 2 buttons.  I should be able to go into my Main Activity and simply call &quot;btnStartService&quot; and implement an onlicklistener.  Android Studio will not populate the id for either button within the main activity.  What am I forgetting...</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      tools:context=&quot;.MainActivity&quot;&gt;
  
      &lt;TextView
          android:id=&quot;@+id/textView&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:text=&quot;Service Stopped!&quot;
          android:textSize=&quot;25sp&quot;
          app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
          app:layout_constraintLeft_toLeftOf=&quot;parent&quot;
          app:layout_constraintRight_toRightOf=&quot;parent&quot;
          app:layout_constraintTop_toTopOf=&quot;parent&quot; /&gt;
  
      &lt;Button
          android:id=&quot;@+id/btnStopService&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:text=&quot;Stop&quot;
          app:layout_constraintBottom_toTopOf=&quot;@+id/textView&quot;
          app:layout_constraintEnd_toStartOf=&quot;@+id/btnStartService&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toTopOf=&quot;parent&quot; /&gt;
  
      &lt;Button
          android:id=&quot;@+id/btnStartService&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:text=&quot;Start&quot;
          app:layout_constraintBottom_toTopOf=&quot;@+id/textView&quot;
          app:layout_constraintTop_toTopOf=&quot;parent&quot;
          tools:layout_editor_absoluteX=&quot;260dp&quot;
          tools:ignore=&quot;MissingConstraints&quot; /&gt;
  
  &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  </code></pre>
  <pre><code>package com.dev20.servicepractice
  
  import androidx.appcompat.app.AppCompatActivity
  import android.os.Bundle
  
  class MainActivity : AppCompatActivity() {
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_main)
      
          // This is where Android Studio cannot find the reference
          btnStartService
  
      }
  }
  </code></pre>
  <p>I could do something like this, but it does not look as clean.  I used to be able to simply call the button without first initializing it with findbyviewid</p>
  <pre><code>        // This is where Android Studio cannot find the reference
          val btnStartService = findViewById&lt;Button&gt;(R.id.btnStartService)
          btnStartService.setOnClickListener { 
              
          }
      }
  }
  </code></pre>