Java.lang.ClassCastException: android.widget.TextView could not be added

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 get above the error, if someone knows, then tell me ... I am very grateful


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> 
+6
source share
5 answers

Delete R.java Clean project Save files Build and run

+45
source
 <TextView android:id="@+id/t" ... /> <TextView android:id="@+id/des" ... /> 
 EditText t=(EditText) findViewById(R.id.t); EditText d=(EditText) findViewById(R.id.des); 

Want TextViews or EditTexts?

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

+5
source

I could solve this by simply cleaning up the project using project / cleanup.

+4
source

If there is a problem with cleaning, then it may throw any casting error. I got it:

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

In eclipse, just go to Project> Clean and select your project to clean it.

+1
source

You are using textview in xml, but in the action you are trying EditText t = (EditText) findViewById (R.id.t) is incorrect; using TextView t = (TextView) findViewById (R.id.t);

or change xml TextView to EditText

0
source

All Articles