9
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>
4
  • 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. Commented Dec 2, 2012 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); Commented Dec 2, 2012 at 22:37
  • <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> Commented Dec 2, 2012 at 22:38
  • 1
    Use "edit" to add this information to your question in the appropirate format. Commented Dec 2, 2012 at 22:39

5 Answers 5

46

Delete R.java Clean project Save files Build & Run

Sign up to request clarification or add additional context in comments.

4 Comments

Ugh, thanks, that's usually my default. Stuff like this drives me batty.
This is simple and superb answer saved my life
I was beginning to lose the will to live. Thanks for restoring my faith in Android development!
Simply cleaning the project worked for me, but I +1 this anyways.
7
<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...

1 Comment

Oh my God...Big blooper. Thanks for help
4

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

Comments

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.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.