Android java.lang.ClassCastException: android.widget.RelativeLayout cannot be cast to android.widget.EditText

后端 未结 3 1226
萌比男神i
萌比男神i 2021-01-20 20:54

I get the following exception in Android when clicking a button to take me from an activity to another (I\'m new in Android development, so it may not be the brightest of qu

相关标签:
3条回答
  • 2021-01-20 21:39

    I received this error when my main activity.xml did not have the include statement to my content.xml file.

    Once i added these lines back into my main activity.xml file, everything was fine again.

        <include
        android:id="@+id/editText"
        layout="@layout/content" />
    
    0 讨论(0)
  • 2021-01-20 21:42

    android:id="@+id/editCustomerPhone"

    remove this line

    from below tag

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

    you have set it twice. One for relative layout one for edittext

    0 讨论(0)
  • 2021-01-20 21:49

    you code says :

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/editCustomerPhone"
    

    editCustomerPhone is a relativelayout.

    0 讨论(0)
提交回复
热议问题