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

前端 未结 5 980
醉梦人生
醉梦人生 2020-12-30 13:08
12-01 00:36:28.058: E/AndroidRuntime(5062): Caused by: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.EditText
相关标签:
5条回答
  • 2020-12-30 13:25

    If there is a cleanup issue then it can throw any casting error.I got this:

    Caused by: java.lang.ClassCastException: android.widget.EditText cannot be cast to android.widget.LinearLayout
    

    In eclipse, Just go to Project > Clean & Select your project to clean it.

    0 讨论(0)
  • 2020-12-30 13:29
    <TextView android:id="@+id/t" ... /> 
    <TextView android:id="@+id/des" ... />
    
    EditText t=(EditText) findViewById(R.id.t);
    EditText d=(EditText) findViewById(R.id.des);
    

    Do you want TextViews or EditTexts?

    Either change the XML to use EditTexts or the Java to use TextViews...

    0 讨论(0)
  • 2020-12-30 13:31

    Delete R.java Clean project Save files Build & Run

    0 讨论(0)
  • 2020-12-30 13:41

    You use textview in xml, but in the activity you try to EditText t=(EditText) findViewById(R.id.t) - not correct; use TextView t=(TextView) findViewById(R.id.t);

    or change in xml TextView to EditText

    0 讨论(0)
  • 2020-12-30 13:42

    I could solve it by just cleaning the project with project/clean.

    0 讨论(0)
提交回复
热议问题