[英]java.lang.ClassCastException: android.widget.TextView cannot be cast
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: 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: 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>
删除R.java清理项目保存文件构建和运行
<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? 你想要TextViews还是EditTexts?
Either change the XML to use EditTexts or the Java to use TextViews... 更改XML以使用EditTexts或Java来使用TextViews ...
我可以通过使用project / clean清理项目来解决它。
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. 在eclipse中,只需转到Project> Clean&Select您的项目进行清理。
You use textview in xml, but in the activity you try to EditText t=(EditText) findViewById(R.id.t) - not correct; 你在xml中使用textview,但在你尝试EditText的活动中t =(EditText)findViewById(R.id.t) - 不正确; use TextView t=(TextView) findViewById(R.id.t);
使用TextView t =(TextView)findViewById(R.id.t);
or change in xml TextView to EditText 或者将xml TextView更改为EditText
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.