Android-java.lang.Classcastexception-Fehler: android.- widget.RelativeLayout können nicht umgewandelt werden, android.- widget.EditText
Bekomme ich die folgende exception in Android beim klicken auf eine Schaltfläche, um mich von einer Aktivität zu anderen (ich bin neu in der Android Entwicklung, so ist es vielleicht nicht die hellsten Fragen):
java.lang.Classcastexception-Fehler: android.- widget.RelativeLayout können nicht umgewandelt werden, android.- widget.EditText
Ich habe versucht, die Reinigung der Projekt mehrere Male, ich habe versucht, die option Fix Project Properties von Android-Tools, ich habe mein xml für die Fehler, aber ich kann einfach nicht scheinen, um dies herauszufinden. Ich muss noch erwähnen, dass der Knopf gut funktioniert für einige Zeit, bis diese Ausnahme aufgetreten.
Hier ist mein xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/editCustomerPhone"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/background_dark"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".CustomerInfoActivity" >
<FrameLayout
android:id="@+id/frameLayout1"
android:layout_width="wrap_content"
android:layout_height="250dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="@drawable/ic_new_delivery" >
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Insert Customer Data:"
android:textColor="@color/light_blue"
android:textSize="20sp"
android:textStyle="italic" />
</FrameLayout>
<EditText
android:id="@+id/editCustomerName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView1"
android:layout_alignBottom="@+id/textView1"
android:layout_alignParentRight="true"
android:ems="10"
android:inputType="textPersonName"
android:textColor="@color/light_blue" />
<Button
android:id="@+id/submitInfoBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_alignParentBottom="true"
android:layout_alignRight="@+id/editCustomerName"
android:text="Submit Info"
android:textColor="@color/light_red"
android:onClick="submitCustomerInfo"/>
<EditText
android:id="@+id/editCustomerPhone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editCustomerName"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/TextView01"
android:ems="10"
android:inputType="phone"
android:textColor="@color/light_red" >
<requestFocus />
</EditText>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/frameLayout1"
android:text="Name:"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/background_light"
android:textStyle="bold"
android:typeface="serif" />
<TextView
android:id="@+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/editCustomerPhone"
android:layout_marginTop="14dp"
android:text="Email:"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/background_light"
android:textStyle="bold"
android:typeface="serif" />
<EditText
android:id="@+id/editCustomerEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/TextView02"
android:layout_alignBottom="@+id/TextView02"
android:layout_alignLeft="@+id/editCustomerPhone"
android:layout_alignParentRight="true"
android:ems="10"
android:inputType="textEmailAddress"
android:textColor="@color/light_green" />
<TextView
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/TextView02"
android:layout_below="@+id/editCustomerName"
android:layout_marginTop="19dp"
android:text="Phone:"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/background_light"
android:textStyle="bold"
android:typeface="serif" />
Hier ist mein onCreate-Methode in der Aktivität, die die Ausnahme ausgelöst:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_customer_info);
this.editMail = (EditText)findViewById(R.id.editCustomerEmail);
this.editName = (EditText)findViewById(R.id.editCustomerName);
this.editPhone = (EditText)findViewById(R.id.editCustomerPhone); //the exception points me here
}
InformationsquelleAutor barca_d | 2014-01-06
Du musst angemeldet sein, um einen Kommentar abzugeben.
du code sagt :
editCustomerPhone
ist ein relativelayout.Wie kam ich vermisse die... ich denke, es ist die Eclipse-designer Schuld, der für die Herstellung der xml-hinter so chaotisch und ungeordnet
diese Art von Problemen löst eine Warnung aus, daß
Duplicate id, already defined ...
im xml-editor. Könnte es etwas falsch mit Ihrer Konfiguration, aber.InformationsquelleAutor njzk2
entfernen Sie diese Zeile
unten tag
es zweimal. Eine für relative layout für eine edittext
InformationsquelleAutor Sush
Erhielt ich diese Fehlermeldung, wenn mein main activity.xml nicht über die include-Anweisung zu meinem content.xml Datei.
Sobald ich fügte diese Zeilen wieder in mein main activity.xml Datei war alles wieder gut.
InformationsquelleAutor Adam M. Erickson