小编Han*_* .T的帖子

java.lang.ClassCastException:android.widget.LinearLayout无法强制转换为android.widget.TextView

我使用我的应用程序时出现此错误:

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
Run Code Online (Sandbox Code Playgroud)

问题的方法:

public void onItemClick(AdapterView<?> 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);
}
Run Code Online (Sandbox Code Playgroud)

和XML文件:

<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" …
Run Code Online (Sandbox Code Playgroud)

android textview android-linearlayout

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

android ×1

android-linearlayout ×1

textview ×1