title: java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.widget.TextView using ArrayAdapter
body: <p>I'm working on my term project which developed on Android device.
  The problem is I try to add an object into my ArrayAdapter.
  But it gets an errors.</p>
  
  <pre><code>11-29 11:58:07.136: D/dalvikvm(1262): GC_FOR_ALLOC freed 136K, 8% free 2677K/2880K, paused 30ms, total 32ms
  
  11-29 11:58:07.415: E/ArrayAdapter(1262): You must supply a resource ID for a TextView
  
  11-29 11:58:07.415: D/AndroidRuntime(1262): Shutting down VM
  
  11-29 11:58:07.415: W/dalvikvm(1262): threadid=1: thread exiting with uncaught exception (group=0x41465700)
  
  11-29 11:58:07.465: E/AndroidRuntime(1262): FATAL EXCEPTION: main
  
  11-29 11:58:07.465: E/AndroidRuntime(1262): java.lang.IllegalStateException: ArrayAdapter requires the resource ID to be a TextView
  
  11-29 11:58:07.465: E/AndroidRuntime(1262):     at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:386)
  
  11-29 11:58:07.465: E/AndroidRuntime(1262):     at android.widget.ArrayAdapter.getView(ArrayAdapter.java:362)
  
  11-29 11:58:07.465: E/AndroidRuntime(1262):     at android.widget.AbsListView.obtainView(AbsListView.java:2177)
  
  11-29 11:58:07.465: E/AndroidRuntime(1262):     at android.widget.ListView.makeAndAddView(ListView.java:1840)
  
  11-29 11:58:07.465: E/AndroidRuntime(1262):     at android.widget.ListView.fillDown(ListView.java:675)
  
  11-29 11:58:07.465: E/AndroidRuntime(1262):     at android.widget.ListView.fillFromTop(ListView.java:736)
  
  11-29 11:58:07.465: E/AndroidRuntime(1262):     at android.widget.ListView.layoutChildren(ListView.java:1655)
  
  11-29 11:58:07.465: E/AndroidRuntime(1262):     at android.widget.AbsListView.onLayout(AbsListView.java:2012)
  
  11-29 11:58:07.465: E/AndroidRuntime(1262):     at android.view.View.layout(View.java:14289)
  
  11-29 11:58:07.465: E/AndroidRuntime(1262):     at android.view.ViewGroup.layout(ViewGroup.java:4562)
  
  11-29 11:58:07.465: E/AndroidRuntime(1262):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
  
  11-29 11:58:07.465: E/AndroidRuntime(1262):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
  
  11-29 11:58:07.465: E/AndroidRuntime(1262):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
  
  11-29 11:58:07.465: E/AndroidRuntime(1262):     at android.view.View.layout(View.java:14289)
  
  11-29 11:58:07.465: E/AndroidRuntime(1262):     at android.view.ViewGroup.layout(ViewGroup.java:4562)
  
  11-29 11:58:07.465: E/AndroidRuntime(1262):     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
  
  11-29 11:58:07.465: E/AndroidRuntime(1262):     at android.view.View.layout(View.java:14289)
  
  11-29 11:58:07.465: E/AndroidRuntime(1262):     at android.view.ViewGroup.layout(ViewGroup.java:4562)
  
  11-29 11:58:07.465: E/AndroidRuntime(1262):     at com.android.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:349)
  
  11-29 11:58:07.465: E/AndroidRuntime(1262):     at android.view.View.layout(View.java:14289)
  
  11-29 11:58:07.465: E/AndroidRuntime(1262):     at android.view.ViewGroup.layout(ViewGroup.java:4562)
  
  11-29 11:58:07.465: E/AndroidRuntime(1262):     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
  
  11-29 11:58:07.465: E/AndroidRuntime(1262):     at android.view.View.layout(View.java:14289)
  
  11-29 11:58:07.465: E/AndroidRuntime(1262):     at android.view.ViewGroup.layout(ViewGroup.java:4562)
  
  11-29 11:58:07.465: E/AndroidRuntime(1262):     at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1976)
  
  11-29 11:58:07.465: E/AndroidRuntime(1262):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1730)
  
  11-29 11:58:07.465: E/AndroidRuntime(1262):     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
  
  11-29 11:58:07.465: E/AndroidRuntime(1262):     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
  
  11-29 11:58:07.465: E/AndroidRuntime(1262):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
  
  11-29 11:58:07.465: E/AndroidRuntime(1262):     at android.view.Choreographer.doCallbacks(Choreographer.java:562)
  
  11-29 11:58:07.465: E/AndroidRuntime(1262):     at android.view.Choreographer.doFrame(Choreographer.java:532)
  
  11-29 11:58:07.465: E/AndroidRuntime(1262):     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
  
  11-29 11:58:07.465: E/AndroidRuntime(1262):     at android.os.Handler.handleCallback(Handler.java:730)
  
  11-29 11:58:07.465: E/AndroidRuntime(1262):     at android.os.Handler.dispatchMessage(Handler.java:92)
  
  11-29 11:58:07.465: E/AndroidRuntime(1262):     at android.os.Looper.loop(Looper.java:137)
  
  11-29 11:58:07.465: E/AndroidRuntime(1262):     at android.app.ActivityThread.main(ActivityThread.java:5103)
  
  11-29 11:58:07.465: E/AndroidRuntime(1262):     at java.lang.reflect.Method.invokeNative(Native Method)
  
  11-29 11:58:07.465: E/AndroidRuntime(1262):     at java.lang.reflect.Method.invoke(Method.java:525)
  
  11-29 11:58:07.465: E/AndroidRuntime(1262):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
  
  11-29 11:58:07.465: E/AndroidRuntime(1262):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
  
  11-29 11:58:07.465: E/AndroidRuntime(1262):     at dalvik.system.NativeStart.main(Native Method)
  
  11-29 11:58:07.465: E/AndroidRuntime(1262): Caused by: java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.widget.TextView
  
  11-29 11:58:07.465: E/AndroidRuntime(1262):     at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:379)
  
  11-29 11:58:07.465: E/AndroidRuntime(1262):     ... 40 more
  </code></pre>
  
  <p>This is my MainActivity - <strong>onCreate method.</strong></p>
  
  <pre><code>private EditText createTaskText;
  ArrayAdapter&lt;Task&gt; listAdapter;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState); // To change body of overridden
                                          // methods use File | Settings |
                                          // File Templates.
      setContentView(R.layout.main);
  
      // !!! Add quick create task !!!
      createTaskText = (EditText) findViewById(R.id.quickTopic);
      TextView.OnEditorActionListener exListener = new TextView.OnEditorActionListener() {
  
          @Override
          public boolean onEditorAction(TextView v, int actionId,
                  KeyEvent event) {
              if (actionId == EditorInfo.IME_NULL
                      &amp;&amp; event.getAction() == KeyEvent.ACTION_DOWN
                      &amp;&amp; !createTaskText.getText().toString().equals("")) {
                  // setContentView(R.layout.edit_task_page);
                  Intent goTaskEdit = new Intent(ExpandAnimationDemo.this,
                          TaskEdit.class);
                  goTaskEdit.putExtra("Topic", createTaskText.getText()
                          .toString());
                  startActivity(goTaskEdit);
                  createTaskText.setText("");
              }
              return false;
          }
      };
      createTaskText.setOnEditorActionListener(exListener);
  
  
      // Creating list, initially = 0 list
      ListView list = (ListView) findViewById(R.id.udiniList);
  
      Task[] items = {
              new Task("Task 1"),
              new Task("Task 2"),
              new Task("Task 3"),
              new Task("Task 4"),
              new Task("Task 5"),
              };
      // Creating the list adapter and populating the list
      listAdapter = new ArrayAdapter&lt;Task&gt;(this,
              R.layout.list_item, items);
      list.setAdapter(listAdapter);
  
  
      // Creating an item click listener, to open/close our toolbar for each
      // item
      list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
          public void onItemClick(AdapterView&lt;?&gt; parent, final View view,
                  int position, long id) {
  
              View toolbar = view.findViewById(R.id.toolbar);
  
              // Creating the expand animation for the item
              ExpandAnimation expandAni = new ExpandAnimation(toolbar, 500);
  
              // Start the animation on the toolbar
              toolbar.startAnimation(expandAni);
  
          }
      });
  
      // !!! Set Swipe to Dismiss !!!
      // Create a ListView-specific touch listener. ListViews are given special treatment because
      // by default they handle touches for their list items... i.e. they're in charge of drawing
      // the pressed state (the list selector), handling list item clicks, etc.
      SwipeDismissListViewTouchListener touchListener =
              new SwipeDismissListViewTouchListener(
                      list,
                      new SwipeDismissListViewTouchListener.DismissCallbacks() {
                          @Override
                          public boolean canDismiss(int position) {
                              return true;
                          }
  
                          @Override
                          public void onDismiss(ListView listView, int[] reverseSortedPositions) {
                              for (int position : reverseSortedPositions) {
                                  listAdapter.remove(listAdapter.getItem(position));
                              }
                              listAdapter.notifyDataSetChanged();
                          }
                      });
      list.setOnTouchListener(touchListener);
      // Setting this scroll listener is required to ensure that during ListView scrolling,
      // we don't look for swipes.
      list.setOnScrollListener(touchListener.makeScrollListener());
  
  }
  </code></pre>
  
  <p><strong>My Task class</strong></p>
  
  <pre><code>public class Task extends HistoryTask {
  
  int priority;
  Calendar duedate;
  
  //------------------------------
  // constructors
  public Task() {
      duedate = Calendar.getInstance();
  }
  
  public Task( String t ) {
      super( t );
      duedate = Calendar.getInstance();
  }
  
  public Task( String t, String d ) {
      super( t, d );
      duedate = Calendar.getInstance();
  }
  
  public Task( String t, String d, int tg ) {
      super( t, d, tg );
      duedate = Calendar.getInstance();
  }
  
  public Task( String t, String d, int tg, int p ) {
      super( t, d, tg );
      priority = p;
      duedate = Calendar.getInstance();
  }
  
  public Task( String t, String d, int tg, int p, Calendar dd ) {
      super( t, d, tg );
      priority = p;
      duedate = dd;
  }   
  
  @Override
  public String toString() {
      return super.toString();
  }
  
  }
  </code></pre>
  
  <p><strong>main.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical" &gt;
  
  &lt;EditText
      android:id="@+id/quickTopic"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_marginLeft="30dp"
      android:layout_marginRight="30dp"
      android:layout_marginTop="10dp"
      android:hint="@string/quickTaskTopic"
      android:inputType="text" /&gt;
  
  &lt;ListView
      android:id="@+id/udiniList"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:divider="@android:color/transparent"
      android:dividerHeight="10.0sp" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><strong>list_item.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical" &gt;
  
  &lt;RelativeLayout
      android:layout_width="fill_parent"
      android:layout_height="wrap_content" &gt;
  
      &lt;TextView
          android:id="@+id/title"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:focusable="false"
          android:focusableInTouchMode="false"
          android:padding="20dip" /&gt;
  
      &lt;ImageView
          android:id="@+id/editPic"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginRight="10dp"
          android:layout_marginTop="20dp"
          android:layout_toLeftOf="@+id/deletePic"
          android:contentDescription="@string/EditDesc"
          android:src="@drawable/pencil" /&gt;
  
      &lt;ImageView
          android:id="@+id/deletePic"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentRight="true"
          android:layout_marginRight="20dp"
          android:layout_marginTop="20dp"
          android:contentDescription="@string/DeleteDesc"
          android:src="@drawable/delete" /&gt;
  &lt;/RelativeLayout&gt;
  
  &lt;!-- *********************** --&gt;
  &lt;!-- *** TOOLBAR LAYOUT **** --&gt;
  &lt;!-- *********************** --&gt;
  
  &lt;LinearLayout
      android:id="@+id/toolbar"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_marginBottom="-20dip"
      android:orientation="vertical"
      android:visibility="gone" &gt;
  
      &lt;!-- TextView will showing task details.The details must get from user database --&gt;
  
      &lt;TextView
          android:id="@+id/taskDetail"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:focusable="false"
          android:focusableInTouchMode="false"
          android:padding="20dp"
          android:paddingLeft="50dp"
          android:singleLine="false"
          android:text="@string/Details" /&gt;
  
      &lt;!-- This RelativeLayout manage the TextView which represent the information of Priority, DueDate, and Tag s--&gt;
  
      &lt;RelativeLayout
          android:id="@+id/taskSpec"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:focusable="false"
          android:focusableInTouchMode="false" &gt;
  
          &lt;!-- TextView of "Priority" and priority value --&gt;
  
          &lt;TextView
              android:id="@+id/PriorityStr"
              android:layout_width="100dp"
              android:layout_height="wrap_content"
              android:padding="20dp"
              android:paddingLeft="50dp"
              android:text="@string/Priority" /&gt;
  
          &lt;TextView
              android:id="@+id/PriorityGet"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_toRightOf="@+id/PriorityStr"
              android:padding="20dp"
              android:paddingLeft="55dp"
              android:text="@string/SamplePriority" /&gt;
  
          &lt;!-- TextView of "DueDate" and duedate value --&gt;
  
          &lt;TextView
              android:id="@+id/DueDateStr"
              android:layout_width="100dp"
              android:layout_height="wrap_content"
              android:layout_below="@+id/PriorityStr"
              android:padding="20dp"
              android:paddingLeft="50dp"
              android:text="@string/DueDate" /&gt;
  
          &lt;TextView
              android:id="@+id/DueDateGet"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_below="@+id/PriorityGet"
              android:layout_toRightOf="@+id/DueDateStr"
              android:padding="20dp"
              android:paddingLeft="50dp"
              android:text="@string/SampleDueDate" /&gt;
  
          &lt;!-- TextView of "Tags" and tags value --&gt;
  
          &lt;TextView
              android:id="@+id/TagsStr"
              android:layout_width="100dp"
              android:layout_height="wrap_content"
              android:layout_below="@+id/DueDateStr"
              android:padding="20dp"
              android:paddingLeft="50dp"
              android:text="@string/Tags" /&gt;
  
          &lt;TextView
              android:id="@+id/TagGet"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_below="@+id/DueDateGet"
              android:layout_toRightOf="@+id/TagsStr"
              android:padding="20dp"
              android:paddingLeft="60dp"
              android:text="@string/SampleTags" /&gt;
      &lt;/RelativeLayout&gt;
  &lt;/LinearLayout&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>How can I solve this problem?</p>