0

希望周末一切顺利。我正在处理登录和注册页面,很难找到解决未经检查的强制转换错误的方法,经过检查,xml 代码似乎一切正常。挑战真的很令人沮丧,这是代码

爪哇代码

public class RegistrationPage < Button > extends AppCompatActivity {
    EditText emailId, password;
    Button btnSignin;
    TextView tvSign_Up;
    FirebaseAuth mFirebaseAuth;

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

            mFirebaseAuth = FirebaseAuth.getInstance();
            emailId = findViewById(R.id.editTextTextEmailAddress);
            password = findViewById(R.id.editTextTextPassword);
            btnSignin = (Button) findViewById(R.id.Sign_In);
            tvSign_Up = (findViewById(R.id.textView2));
            btnSignin.(new RegistrationPage < > () View.OnClickListener(("v"))) - > {
                    @Override
                    public void onClick(View "V") {
                        string email = emailId.getText().toString();
                        string pwd = password.getText().toString();
                        if (((String) email).isEmpty()) {
                            emailId.setError("Please Enter Correct Email Address");
                            emailId.requestFocus();
                        }

xml代码

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 
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"
tools:context=".RegistrationPage">

<EditText
android:id="@+id/editTextTextEmailAddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="84dp"
android:layout_marginLeft="84dp"
android:layout_marginTop="152dp"
android:layout_marginEnd="85dp"
android:layout_marginRight="85dp"
android:layout_marginBottom="313dp"
android:autofillHints=""
android:ems="10"
android:hint="@string/email"
android:inputType="textEmailAddress"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/editTextTextPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="85dp"
android:layout_marginLeft="85dp"
android:layout_marginEnd="85dp"
android:layout_marginRight="85dp"
android:autofillHints=""
android:ems="10"
android:hint="@string/password"
android:inputType="textPassword"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editTextTextEmailAddress"
app:layout_constraintVertical_bias="0.092" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="29dp"
android:layout_marginBottom="200dp"
android:text="@string/already_have_an_account_sign_in_here"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editTextTextPassword"
app:layout_constraintVertical_bias="0.677" />
<Button
android:id="@+id/Sign_In"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_marginStart="50dp"
android:layout_marginLeft="50dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="50dp"
android:layout_marginRight="50dp"
android:text="@string/sign_up"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editTextTextPassword"
app:layout_constraintVertical_bias="0.054" />

</androidx.constraintlayout.widget.ConstraintLayout>

任何帮助将不胜感激

4

2 回答 2

0

似乎有一些编码格式错误。用这个替换你上面的java代码并尝试一下:

mFirebaseAuth = FirebaseAuth.getInstance();
emailId = findViewById(R.id.editTextTextEmailAddress);
password = findViewById(R.id.editTextTextPassword);
btnSignin = findViewById(R.id.Sign_In);
tvSign_Up = findViewById(R.id.textView2);

btnSignin.setOnClickListener(v -> {
    String email = emailId.getText().toString();
    String pwd = password.getText().toString();
    if (email.isEmpty()) {
        emailId.setError("Please Enter Correct Email Address");
        emailId.requestFocus();
    }
});
于 2021-03-07T23:33:40.010 回答
0

这本身不是错误,而是编译时警告,有时警告无关紧要,有时则无关。

另一种而非解决方案是使用

@SuppressWarnings ("unchecked") 

或者

@Suppress("unchecked")

btnSignin = findViewById(R.id.Sign_In); // remove (Button), is not necesary

抑制警告

@SuppressWarnings指示编译器忽略或抑制带注释的元素中的指定编译器警告以及该元素内的所有程序元素,例如,如果一个类被注释为抑制特定的警告,那么在该类内部的方法期间生成的警告也将是压制。

@SuppressWarnings("unchecked")并且@SuppressWarnings("serial") 是两个最流行的@SuppressWarnings 注释示例。此外,如果您限制范围,这样它甚至不会影响整个方法。

SuppressWarnings 表示潜在的编程错误或错误,因此建议谨慎使用它们,而是尝试解决触发该警告的实际问题。但是在某些情况下,当您绝对确定事情不会出错时,您可以使用@SuppressWarnings来抑制这些警告。

于 2021-03-08T00:56:43.877 回答