8
12-01 00:36:28.058: E/AndroidRuntime(5062): Caused by: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.EditText

I am getting above error if anyone knows then tell me ...i shall very thankful


Java:

Log.d("Textra", title); 
Log.d("Dextra", des); 
EditText t=(EditText) findViewById(R.id.t); 
EditText d=(EditText) findViewById(R.id.des); 
t.setText(title); 
d.setText(des);

XML:

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 

    <TextView 
        android:id="@+id/t" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="" 
        android:textAppearance="?android:attr/textAppearanceLarge" /> 

    <TextView 
        android:id="@+id/des" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text=""/> 

</LinearLayout>
Sam
  • 86,580
  • 20
  • 181
  • 179
Coder
  • 119
  • 1
  • 3
  • 9
  • The error is simple, but please post your relevant Java code, XML code, and all of the LogCat errors so we can where it is happening. – Sam Dec 02 '12 at 22:30
  • java code: Log.d("Textra", title); Log.d("Dextra", des); EditText t=(EditText) findViewById(R.id.t); EditText d=(EditText) findViewById(R.id.des); t.setText(title); d.setText(des); – Coder Dec 02 '12 at 22:37
  • 1
    Use "[edit]" to add this information to your question in the appropirate format. – Sam Dec 02 '12 at 22:39

5 Answers5

46

Delete R.java Clean project Save files Build & Run

AnDx
  • 824
  • 8
  • 11
6
<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...

Sam
  • 86,580
  • 20
  • 181
  • 179
4

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

Allfarid Morales García
  • 1,455
  • 2
  • 17
  • 27
1

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.

Sumoanand
  • 8,835
  • 2
  • 47
  • 46
0

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

Yereke
  • 1