title: Kotlin Cannot Inflate Layout
body: <p>I am building an application that has a <code>GridView</code> that contains a dynamic amount of <code>CardView</code>s.  I am having issues accessing the <code>TextView</code> elements in the individual items layout from the custom adapter that I am creating.</p>
  <p><code>tvCastleName</code> and <code>tvShieldTime</code> are unresolved references, and the application will not compile.</p>
  <p><strong>main.xml</strong></p>
  <pre class="lang-xml prettyprint-override"><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;&gt;
  
  
      &lt;TextView
          android:id=&quot;@+id/tvNickname&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:fontFamily=&quot;sans-serif-medium&quot;
          android:text=&quot;Nickname&quot;
          android:textAppearance=&quot;@style/TextAppearance.AppCompat.Large&quot;
          android:textSize=&quot;24sp&quot;
          app:layout_constraintTop_toTopOf=&quot;parent&quot; /&gt;
  
      &lt;GridView
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;wrap_content&quot;
          app:layout_constraintTop_toBottomOf=&quot;@id/tvNickname&quot;
          android:horizontalSpacing=&quot;6dp&quot;
          android:verticalSpacing=&quot;6dp&quot;
          android:numColumns=&quot;3&quot;
          android:id=&quot;@+id/gvCastles&quot; /&gt;
  </code></pre>
  <p><strong>items.xml</strong></p>
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;androidx.cardview.widget.CardView xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;120dp&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      android:layout_gravity=&quot;center&quot;
      android:layout_margin=&quot;5dp&quot;
      app:cardElevation=&quot;5dp&quot;&gt;
  
      &lt;androidx.constraintlayout.widget.ConstraintLayout
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;match_parent&quot;&gt;
  
          &lt;TextView
              android:id=&quot;@+id/tvCastleName&quot;
              android:layout_width=&quot;match_parent&quot;
              android:layout_height=&quot;wrap_content&quot;
              app:layout_constraintTop_toTopOf=&quot;parent&quot;
              app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
              app:layout_constraintStart_toStartOf=&quot;parent&quot;
              android:fontFamily=&quot;sans-serif-medium&quot;
              android:text=&quot;Castle Name&quot;
              android:gravity=&quot;center&quot;
              android:textAppearance=&quot;@style/TextAppearance.AppCompat.Large&quot; /&gt;
  
          &lt;TextView
              android:layout_width=&quot;match_parent&quot;
              android:layout_height=&quot;wrap_content&quot;
              app:layout_constraintTop_toBottomOf=&quot;@+id/tvCastleName&quot;
              android:text=&quot;15:00&quot;
              android:id=&quot;@+id/tvShieldTime&quot;
              android:gravity=&quot;center&quot; /&gt;
  
      &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  
  &lt;/androidx.cardview.widget.CardView&gt;
  </code></pre>
  <p><strong>GridAdapter.kt</strong></p>
  <pre class="lang-kt prettyprint-override"><code>import android.content.Context
  import android.view.LayoutInflater
  import android.view.View
  import android.view.ViewGroup
  import android.widget.BaseAdapter
  
  class GridAdapter(var nameList: ArrayList&lt;Castle&gt;, var context: Context?) : BaseAdapter() {
  
  
    override fun getCount(): Int = nameList.size
  
    override fun getItem(position: Int): Castle = nameList[position]
  
    override fun getItemId(position: Int): Long {
      TODO(&quot;Not yet implemented&quot;)
    }
  
    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
      val nameList = this.nameList[position]
      var inflater = context!!.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
      val castleView = inflater.inflate(R.layout.items, null)
      castleView.tvCastleName.text = nameList.name!!
      castleView.tvShieldTime.text = &quot;15:00&quot;
      
      return castleView
    }
  
  }
  </code></pre>