我的代码运行良好,但今天运行后出现了下一个错误:
androidx.appcompat.widget.AppCompatButton无法转换为com.google.android.material.textfield.TextInputLayout
第92行的错误:verify_code = findViewById(R.id.verify_code);
当活动开始时,应用程序中断,我得到以下错误
java代码
public class PhoneLoginActivity extends AppCompatActivity {
private EditText InputUserPhoneNumber, InputUserVerificationCode;
private Button SendVerificationCodeButton, VerifyButton;
private long backPressedTime;
private Toast backToast;
ProgressDialog progressDialog;
private PhoneAuthProvider.OnVerificationStateChangedCallbacks callbacks;
private FirebaseAuth mAuth;
private TextInputLayout phone_num;
private TextInputLayout verify_code;
private ProgressDialog loadingBar;
private DatabaseReference dbRef;
private FirebaseDatabase mFirebaseDatabase;
private String mVerificationId;
String lat;
private StorageReference mStorageRef;
String uid;
String lng;
String phone_number;
private PhoneAuthProvider.ForceResendingToken mResendToken;
public static final int Request_Code_Granded_Premission = 1408;
private static final String TAG = "PhoneLoginActivity";
private String ph_num;
boolean check = false;
private String phone_jor;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
mStorageRef = FirebaseStorage.getInstance().getReference();
mFirebaseDatabase = FirebaseDatabase.getInstance();
dbRef = mFirebaseDatabase.getReference("Guest");
InputUserPhoneNumber = (EditText) findViewById(R.id.phone_text);
InputUserVerificationCode = (EditText) findViewById(R.id.pwd_text);
SendVerificationCodeButton = (Button) findViewById(R.id.login_btn);
VerifyButton = (Button) findViewById(R.id.verify_button);
loadingBar = new ProgressDialog(this);
phone_num = findViewById(R.id.phone_number);
verify_code = findViewById(R.id.verify_code);
phone_number = InputUserPhoneNumber.getText().toString();
.
.
.
}
}
xml代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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="#fff"
android:id="@+id/log_in"
android:scrollbars="vertical"
android:paddingBottom="30dp"
tools:context=".Activities.PhoneLoginActivity"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView
android:id="@+id/circle"
android:layout_width="146dp"
android:layout_height="121dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
app:srcCompat="@drawable/circle_logo" />
<TextView
android:id="@+id/hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_below="@+id/circle"
android:layout_centerHorizontal="true"
android:layout_marginRight="5dp"
android:layout_marginTop="10dp"
android:gravity="center"
android:text="@string/hello_word"
android:textSize="14dp" />
<TextView
android:layout_below="@+id/hello"
android:id="@+id/hello2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_centerHorizontal="true"
android:layout_marginRight="5dp"
android:layout_marginTop="25dp"
android:textColor="#000"
android:gravity="center"
android:text="@string/hello2"
android:textSize="14dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/hello2"
android:gravity="top|center"
android:layout_marginTop="5dp"
android:orientation="vertical"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/phone_number"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:theme="@style/TextLabel">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/phone_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:ems="10"
android:hint="@string/ed_phone"
android:inputType="phone"
android:textColor="#064065"
android:textColorHint="#064065"
/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/verify_code"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="-75dp"
android:layout_marginBottom="15dp"
android:gravity="center"
android:theme="@style/TextLabel"
android:visibility="invisible">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/pwd_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="@string/ed_pwd"
android:inputType="number"
android:textColor="#064065"
android:textColorHint="#064065"
/>
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="@+id/login_btn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:background="@drawable/btn_login"
android:text="@string/login"
android:textColor="@android:color/white"
/>
<Button
android:id="@+id/verify_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="-50dp"
android:text="@string/verify"
android:textColor="@android:color/black"
android:visibility="invisible" />
</LinearLayout>
</RelativeLayout>
和erorr
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.awshakam1998.bottleofwater, PID: 31185
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.awshakam1998.bottleofwater/com.awshakam1998.bottleofwater.Activities.PhoneLoginActivity}: java.lang.ClassCastException: androidx.appcompat.widget.AppCompatButton cannot be cast to com.google.android.material.textfield.TextInputLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3194)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3302)
at android.app.ActivityThread.-wrap12(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1891)
at android.os.Handler.dispatchMessage(Handler.java:108)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7425)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
Caused by: java.lang.ClassCastException: androidx.appcompat.widget.AppCompatButton cannot be cast to com.google.android.material.textfield.TextInputLayout
at com.awshakam1998.bottleofwater.Activities.PhoneLoginActivity.onCreate(PhoneLoginActivity.java:92)
at android.app.Activity.performCreate(Activity.java:7372)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1218)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3147)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3302)
at android.app.ActivityThread.-wrap12(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1891)
at android.os.Handler.dispatchMessage(Handler.java:108)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7425)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
我认为,代码中没有错误。你能从设备上卸载该应用程序吗?重建并重新安装该应用程序。