Widgets aren't being casted. how do I fix it?

送分小仙女□ 提交于 2021-01-28 22:11:45

问题


Whenever I click the sign in button in my app, it just crashes and shows an error. Here is my activity_sign_in.xml and my SignIn.java.

activity_sign_in.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@mipmap/background1"
    tools:context=".SignIn">

    <LinearLayout
        android:orientation="vertical"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_centerInParent="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <com.rengwuxian.materialedittext.MaterialEditText
            android:id="@+id/editPhone"
            android:hint="Phone Number"
            android:textColorHint="@android:color/white"
            android:text="0988112456"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColor="@android:color/white"
            android:textSize="34sp"
            android:inputType="phone"
            app:met_baseColor="@android:color/white"
            app:met_floatingLabel="highlight"
            app:met_maxCharacters="11"
            app:met_primaryColor="@android:color/white"
            app:met_singleLineEllipsis="true"
            />

        <com.rengwuxian.materialedittext.MaterialEditText
            android:id="@+id/editPassword"
            android:hint="Password"
            android:textColorHint="@android:color/white"
            android:text="IMF"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColor="@android:color/white"
            android:textSize="34sp"
            android:inputType="textPassword"
            app:met_baseColor="@android:color/white"
            app:met_floatingLabel="highlight"
            app:met_maxCharacters="11"
            app:met_primaryColor="@android:color/white"
            app:met_singleLineEllipsis="true"
            />

       <LinearLayout
        android:orientation="horizontal"
        android:weightSum="2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

           <CheckBox
               android:id="@+id/ckbRemember"
               style="@style/Material.Drawable.CheckBox"
               android:layout_width="0dp"
               android:layout_weight="1"
               android:layout_height="wrap_content"
               android:text="Remember Me"
               android:gravity="center_vertical"
               android:textColor="@android:color/white"
               app:cbd_tickColor="@color/colorPrimaryDark"
               app:cbd_strokeColor="@android:color/white"

               />

           <TextView
               android:id="@+id/txtForgotPwd"
               android:textColor="@android:color/white"
               android:text="@string/forgot_pwd"
               android:layout_weight="1"
               android:layout_width="0dp"
               android:layout_height="wrap_content" />

       </LinearLayout>


    </LinearLayout>

    <info.hoang8f.widget.FButton
        android:id="@+id/btnSignIn1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginBottom="8dp"
        android:text="@string/Button2"
        android:textColor="@android:color/white"
        app:cornerRadius="4dp"
        app:fButtonColor="#00A9D440"
        app:shadowColor="#00000000"
        app:shadowEnabled="true"
        app:shadowHeight="5dp" />

</RelativeLayout>

SignIn.java

public class SignIn extends AppCompatActivity {

    EditText editPhone,editPassword;
    Button btnSignIn;
    CheckBox ckbRemember;
    TextView txtForgotPwd;

    FirebaseDatabase database;
    DatabaseReference table_user;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sign_in);

        editPassword = (MaterialEditText)findViewById(R.id.editPassword);
        editPhone    = (MaterialEditText)findViewById(R.id.editPhone);
        btnSignIn    = (Button)findViewById(R.id.btnSignIn1);
        ckbRemember = (CheckBox)findViewById(R.id.ckbRemember);
        txtForgotPwd = (TextView) findViewById(R.id.txtForgotPwd);

"Caused by: java.lang.ClassCastException: android.support.v7.widget.AppCompatTextView cannot be cast to com.rey.material.widget.TextView"


回答1:


Check your imports in SignIn.java. You are probably importing com.rey.material.widget.TextView instead of android.widget.TextView. If you want to use the com.rey TextView instead of the normal one you have to write

 <com.rey.material.widget.TextView
           android:id="@+id/txtForgotPwd"
           android:textColor="@android:color/white"
           ...

in your xml.



来源:https://stackoverflow.com/questions/57010028/widgets-arent-being-casted-how-do-i-fix-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!