. lang。android.widget ClassCastException。TextView不能投

时间:2021-12-09 11:34:25
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>

5 个解决方案

#1


45  

Delete R.javaClean project Save filesBuild & Run

删除R。javaClean项目保存文件构建和运行

#2


5  

<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?

你想要textview还是EditTexts?

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

要么将XML更改为使用EditTexts,要么将Java更改为使用textview…

#3


4  

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

我可以用项目/清洁来解决这个问题。

#4


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.

在eclipse中,只需要进行项目> Clean并选择您的项目来清理它。

#5


0  

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

您在xml中使用textview,但在活动中尝试编辑ext t=(EditText) findViewById(R.id.t) -不正确;useTextView t=(textview) findViewById(R.id.t);

or change in xml TextView to EditText

或者将xml TextView更改为EditText

#1


45  

Delete R.javaClean project Save filesBuild & Run

删除R。javaClean项目保存文件构建和运行

#2


5  

<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?

你想要textview还是EditTexts?

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

要么将XML更改为使用EditTexts,要么将Java更改为使用textview…

#3


4  

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

我可以用项目/清洁来解决这个问题。

#4


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.

在eclipse中,只需要进行项目> Clean并选择您的项目来清理它。

#5


0  

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

您在xml中使用textview,但在活动中尝试编辑ext t=(EditText) findViewById(R.id.t) -不正确;useTextView t=(textview) findViewById(R.id.t);

or change in xml TextView to EditText

或者将xml TextView更改为EditText