java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.widget.TextView

前端 未结 3 1968
囚心锁ツ
囚心锁ツ 2020-12-20 03:26

I\'ve this error when I use my application :

05-01 14:18:41.000: E/AndroidRuntime(26607): FATAL EXCEPTION: main
05-01 14:18:41.000: E/AndroidRuntime(26607):          


        
相关标签:
3条回答
  • 2020-12-20 04:04

    use only

    TextView textview = (TextView)findViewById(R.id.textView1);
    String info = textview.getText().toString();
    
    0 讨论(0)
  • 2020-12-20 04:18

    Use

     TextView textview=((LinearLayout)view).findViewById(R.id.textView1);
     String info = textView.getText().toString(); 
    

    The xml layout file you have provided is not needed here. The list view row file is culprit .so use Id of Textview that is mentioned in row.xml .

    0 讨论(0)
  • 2020-12-20 04:30

    getText() returns an EditableText, not a String. You have to use the toString() method to cast it into a String type:

    String text = (TextView)findViewById(R.id.tv).getText().toString();
    
    0 讨论(0)
提交回复
热议问题