0

エラーが発生しますTextView cannot be cast to EditText.

これは、EditTextが正しい(望ましい)場所になるようにXMLの順序を変更したときに発生します。

それはこの行で起こります:

    EditText edtPassword = (EditText)findViewById(R.id.EditText03);

それらはまったくリンクされていないので、私は困惑しています。

<EditText
    android:id="@+id/EditText03"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:width="160dip" >

</EditText>
<TextView
    android:id="@+id/TextView03"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="UserName:" >

</TextView>
<TextView
    android:id="@+id/TextView04"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Password:">
</TextView>
// IF I MOVE AN EditText03 Here instead it just crashes.
4

1 に答える 1

1

R.javaファイルのTextViewとEditTextのIDが同じ場合に発生することがあると思います

したがって、コードはRファイルを参照しますが、上記のように間違った参照を参照します。

プロジェクトのビューごとに一意のIDを使用する必要があります。

または、prjのすべてのビューに一意のIDがある場合は、プロジェクトをクリーンアップして実行します。

于 2012-05-22T16:07:26.157 に答える