java - 小部件没有被转换。我如何解决它?

标签 java android firebase firebase-realtime-database

每当我单击应用程序中的登录按钮时,它就会崩溃并显示错误。这是我的 Activity_sign_in.xml 和 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);

“引起:java.lang.ClassCastException:android.support.v7.widget.AppCompatTextView无法转换为com.rey.material.widget.TextView”

最佳答案

检查 SignIn.java 中的导入。您可能正在导入 com.rey.material.widget.TextView 而不是 android.widget.TextView。 如果您想使用 com.rey TextView 而不是普通的 TextView,则必须编写

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

在您的 xml 中。

关于java - 小部件没有被转换。我如何解决它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62395737/

相关文章:

java - Jackson - 将接口(interface)反序列化为枚举

Android fragment : When to use hide/show or add/remove/replace?

database - Flutter:如何为我们要上传到Firebase数据库的每个元素设置数据类型?

javascript - 如何在启动 Angular 应用程序之前等待 Firebase 身份验证

ios - 登录功能不工作..抛出错误...Firebase 和 Xcode 9

java - 短信广播接收器未注册

java - 避免 Instant.toEpochMilli() 算术溢出

java - 带 EditText 的进度条

android - 使用Gradle在设备上运行Android应用

android - 使用 Google Places Autocomplete API 的 REQUEST_DENIED 响应