title: Android ExpandableListAdapter: ArrayAdapter requires the resource ID to be a TextView
body: <p>I'm just starting out in Android development and need to create an expandable list view. I'm following this tutorial:
  <a href="http://www.androidhive.info/2013/07/android-expandable-list-view-tutorial/" rel="nofollow noreferrer">http://www.androidhive.info/2013/07/android-expandable-list-view-tutorial/</a></p>
  <p>The application compiles and runs successfully, however I'm getting the following error:</p>
  <blockquote>
  <p>java.lang.IllegalStateException: ArrayAdapter requires the resource ID
  to be a TextView</p>
  </blockquote>
  <p>I have found similar issues on the website, as well as read the <a href="http://developer.android.com/reference/android/widget/ArrayAdapter.html" rel="nofollow noreferrer">Array Adapter documentation</a>, and it seems that I should either:</p>
  <p>A) &quot;<strong>Provide a single TextView as a resource id</strong>. (which I don't want to do, as I want to create a custom layout with an ImageView)&quot;</p>
  <p>-or-</p>
  <p>B) &quot;<strong>Use the constructors that also takes a field id</strong>. That field id should reference a TextView in the larger layout resource.&quot;</p>
  <p>My problem is that the mentioned tutorial doesn't use a simple ArrayAdapter, but a BaseExpandableListAdapter, whose <a href="http://developer.android.com/reference/android/widget/BaseExpandableListAdapter.html#BaseExpandableListAdapter()" rel="nofollow noreferrer">constructor</a> doesn't really accept any paramaters it seems? Where should I pass the reference to the TextView with a BaseExpandableListAdapter?</p>
  <p>I'm extending it as follows:</p>
  <pre><code>package net.jekyllhyde.myapplication;
  
  import android.content.Context;
  import android.graphics.Typeface;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.BaseExpandableListAdapter;
  import android.widget.TextView;
  
  import java.util.HashMap;
  import java.util.List;
  
  public class ExpandableListAdapter extends BaseExpandableListAdapter {
  
      private Context _context;
      private List&lt;String&gt; _listDataHeader; // header titles
      // child data in format of header title, child title
      private HashMap&lt;String, List&lt;String&gt;&gt; _listDataChild;
  
      public ExpandableListAdapter(Context context,
                                   List&lt;String&gt; listDataHeader,
                                   HashMap&lt;String, List&lt;String&gt;&gt; listChildData) {
          this._context = context;
          this._listDataHeader = listDataHeader;
          this._listDataChild = listChildData;
      }
  
      @Override
      public Object getChild(int groupPosition, int childPosititon) {
          return this._listDataChild.get(this._listDataHeader.get(groupPosition))
                  .get(childPosititon);
      }
  
      @Override
      public long getChildId(int groupPosition, int childPosition) {
          return childPosition;
      }
  
      @Override
      public View getChildView(int groupPosition, final int childPosition,
                               boolean isLastChild, View convertView, ViewGroup parent) {
  
          final String childText = (String) getChild(groupPosition, childPosition);
  
          if (convertView == null) {
              LayoutInflater infalInflater = (LayoutInflater) this._context
                      .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              convertView = infalInflater.inflate(R.layout.list_item, parent, false);
          }
  
          TextView txtListChild = (TextView) convertView
                  .findViewById(R.id.lblListItem);
  
          txtListChild.setText(childText);
          return convertView;
      }
  
      @Override
      public int getChildrenCount(int groupPosition) {
          return this._listDataChild.get(this._listDataHeader.get(groupPosition))
                  .size();
      }
  
      @Override
      public Object getGroup(int groupPosition) {
          return this._listDataHeader.get(groupPosition);
      }
  
      @Override
      public int getGroupCount() {
          return this._listDataHeader.size();
      }
  
      @Override
      public long getGroupId(int groupPosition) {
          return groupPosition;
      }
  
      @Override
      public View getGroupView(int groupPosition, boolean isExpanded,
                               View convertView, ViewGroup parent) {
          String headerTitle = (String) getGroup(groupPosition);
          if (convertView == null) {
              LayoutInflater infalInflater = (LayoutInflater) this._context
                      .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              convertView = infalInflater.inflate(R.layout.list_group, parent, false);
          }
  
          TextView lblListHeader = (TextView) convertView
                  .findViewById(R.id.lblListHeader);
          lblListHeader.setTypeface(null, Typeface.BOLD);
          lblListHeader.setText(headerTitle);
  
          return convertView;
      }
  
      @Override
      public boolean hasStableIds() {
          return false;
      }
  
      @Override
      public boolean isChildSelectable(int groupPosition, int childPosition) {
          return true;
      }
  }
  </code></pre>
  <p>I think I'm missing something obvious here (due to my lack of experience with Android) and am thankful for any insight.</p>
  <p>Entire logcat error output, as requested:</p>
  <pre><code>02-15 09:51:11.509  10170-10170/? E/AndroidRuntime? FATAL EXCEPTION: main
  Process: net.jekyllhyde.myapplication, PID: 10170
  java.lang.IllegalStateException: ArrayAdapter requires the resource ID to be a TextView
          at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:386)
          at android.widget.ArrayAdapter.getView(ArrayAdapter.java:362)
          at android.widget.AbsListView.obtainView(AbsListView.java:2263)
          at android.widget.ListView.makeAndAddView(ListView.java:1790)
          at android.widget.ListView.fillDown(ListView.java:691)
          at android.widget.ListView.fillFromTop(ListView.java:752)
          at android.widget.ListView.layoutChildren(ListView.java:1630)
          at android.widget.AbsListView.onLayout(AbsListView.java:2091)
          at android.view.View.layout(View.java:14965)
          at android.view.ViewGroup.layout(ViewGroup.java:4631)
          at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
          at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
          at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
          at android.view.View.layout(View.java:14965)
          at android.view.ViewGroup.layout(ViewGroup.java:4631)
          at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
          at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
          at android.view.View.layout(View.java:14965)
          at android.view.ViewGroup.layout(ViewGroup.java:4631)
          at com.android.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:374)
          at android.view.View.layout(View.java:14965)
          at android.view.ViewGroup.layout(ViewGroup.java:4631)
          at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
          at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
          at android.view.View.layout(View.java:14965)
          at android.view.ViewGroup.layout(ViewGroup.java:4631)
          at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1991)
          at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1748)
          at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
          at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5692)
          at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
          at android.view.Choreographer.doCallbacks(Choreographer.java:574)
          at android.view.Choreographer.doFrame(Choreographer.java:544)
          at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
          at android.os.Handler.handleCallback(Handler.java:733)
          at android.os.Handler.dispatchMessage(Handler.java:95)
          at android.os.Looper.loop(Looper.java:212)
          at android.app.ActivityThread.main(ActivityThread.java:5151)
          at java.lang.reflect.Method.invokeNative(Native Method)
          at java.lang.reflect.Method.invoke(Method.java:515)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:684)
          at dalvik.system.NativeStart.main(Native Method)
  Caused by: java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.widget.TextView
              at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:379) at android.widget.ArrayAdapter.getView(ArrayAdapter.java:362)
  at android.widget.AbsListView.obtainView(AbsListView.java:2263)
              at android.widget.ListView.makeAndAddView(ListView.java:1790)
              at android.widget.ListView.fillDown(ListView.java:691)
              at android.widget.ListView.fillFromTop(ListView.java:752)
              at android.widget.ListView.layoutChildren(ListView.java:1630)
              at android.widget.AbsListView.onLayout(AbsListView.java:2091)
              at android.view.View.layout(View.java:14965)
              at android.view.ViewGroup.layout(ViewGroup.java:4631)
              at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
              at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
              at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
              at android.view.View.layout(View.java:14965)
              at android.view.ViewGroup.layout(ViewGroup.java:4631)
              at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
              at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
              at android.view.View.layout(View.java:14965)
              at android.view.ViewGroup.layout(ViewGroup.java:4631)
              at com.android.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:374)
              at android.view.View.layout(View.java:14965)
              at android.view.ViewGroup.layout(ViewGroup.java:4631)
              at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
              at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
              at android.view.View.layout(View.java:14965)
              at android.view.ViewGroup.layout(ViewGroup.java:4631)
              at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1991)
              at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1748)
              at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
              at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5692)
              at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
              at android.view.Choreographer.doCallbacks(Choreographer.java:574)
              at android.view.Choreographer.doFrame(Choreographer.java:544)
              at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
              at android.os.Handler.handleCallback(Handler.java:733)
              at android.os.Handler.dispatchMessage(Handler.java:95)
              at android.os.Looper.loop(Looper.java:212)
              at android.app.ActivityThread.main(ActivityThread.java:5151)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:515)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:684)
              at dalvik.system.NativeStart.main(Native Method)
  </code></pre>