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

前端 未结 3 1970
囚心锁ツ
囚心锁ツ 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: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();
    

提交回复
热议问题