title: java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.widget.TextView
body: <p>I've this error when I use my application :</p>
  
  <pre><code>05-01 14:18:41.000: E/AndroidRuntime(26607): FATAL EXCEPTION: main
  05-01 14:18:41.000: E/AndroidRuntime(26607): java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.widget.TextView
  </code></pre>
  
  <p>The method with the issue :</p>
  
  <pre><code>public void onItemClick(AdapterView&lt;?&gt; adapterView, View view, int postion,
          long index) {
  
      // Get MAC adress matching the last 17 characters of the TextView
     String info = ((TextView) view).getText().toString();    //  HERE IS THE ISSUE
     String address = info.substring(info.length() - 17);
  
      Intent intent = new Intent();
      intent.putExtra(EXTRA_DEVICE_ADDRESS, address);
  
      setResult(Activity.RESULT_OK, intent);
  
  
      BluetoothDevice device = (BluetoothDevice) view.getTag();
  
      showEquipementActivity(device);
  }
  </code></pre>
  
  <p>And the XML File :</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/linearLayout1"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical" &gt;
  
       &lt;ImageView
          android:id="@+id/ImageView_tactea"
          android:layout_width="200dp"
          android:layout_height="75dp"
          android:src="@drawable/tactea"
          android:layout_gravity="center"
          android:visibility="visible" /&gt;
  
      &lt;LinearLayout
          android:id="@+id/linearLayout2"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:padding="5dip" &gt;
  
          &lt;TextView
              android:id="@+id/textView1"
              android:layout_width="0dip"
              android:layout_height="wrap_content"
              android:layout_weight="1"
              android:text="@string/label_list_of_devices"
              android:textSize="17dip"
              android:textStyle="bold" /&gt;
  
          &lt;Button
              android:id="@+id/buttonScan"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="@string/label_scan" /&gt;
      &lt;/LinearLayout&gt;
  
      &lt;ListView
          android:id="@+id/listViewDevices"
          android:layout_width="fill_parent"
          android:layout_height="0dip"
          android:layout_weight="1" &gt;
      &lt;/ListView&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>This XML file is to display paired bluetooth devices and news devices found.</p>
  
  <p>Can you help me ?</p>
  
  <p>How to change those lines ?</p>
  
  <pre><code>   String info = ((TextView) view).getText().toString();    //  HERE IS THE ISSUE
     String address = info.substring(info.length() - 17);
  </code></pre>
  
  <p>Update: I get following error: </p>
  
  <pre><code>05-01 14:39:33.150: E/AndroidRuntime(7160): FATAL EXCEPTION: main 
  05-01 14:39:33.150: E/AndroidRuntime(7160): java.lang.NullPointerException 
  05-01 14:39:33.150: E/AndroidRuntime(7160): at com.example.cajou.DiscoverDevicesActivity.onItemClick(DiscoverDevicesActivity.ja‌​va:179) 
  05-01 14:39:33.150: E/AndroidRuntime(7160): at android.widget.AdapterView.performItemClick(AdapterView.java:301) 
  05-01 14:39:33.150: E/AndroidRuntime(7160): at android.widget.AbsListView.performItemClick(AbsListView.java:1276)
  </code></pre>
  
  <p>UPDATE 2 :</p>
  
  <p>I've tried :</p>
  
  <pre><code>TextView textview=(TextView) ((LinearLayout)view).findViewById(R.id.textView1);
  String info = textview.getText().toString(); 
  </code></pre>
  
  <p>But I've an issue with this line :</p>
  
  <pre><code>String info = textview.getText().toString(); 
  </code></pre>
  
  <p>UPDATE 3 :</p>
  
  <p>I've tried :</p>
  
  <pre><code>LinearLayout ll = (LinearLayout) view;
  TextView tv = (TextView) ll.findViewById(R.id.textView1);
  final String info = tv.getText().toString();
  </code></pre>
  
  <p>But same issue... 
  This line is the issue :</p>
  
  <pre><code>final String info = tv.getText().toString();
  </code></pre>