gpt4 book ai didi

java - 错误: MainActivity is not abstract and does not override abstract method onClick(View) in OnClickListener

转载 作者:行者123 更新时间:2023-12-01 18:54:21 29 4
gpt4 key购买 nike

我需要帮助解决问题。这可能很简单,但我不知道该怎么做!
我的错误:

error: MainActivity is not abstract and does not override abstract method onClick(View) in OnClickListener

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

Button btRegister;
ImageView circle1;
TextView tvLogin;
Button login;
EditText mEmail,mPassword;
FirebaseAuth fAuth;


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

btRegister = findViewById(R.id.btRegister);
tvLogin = findViewById(R.id.tvLogin);
circle1 = findViewById(R.id.circle1);
login = findViewById(R.id.btLogin);
mEmail = findViewById(R.id.etUsername);
mPassword = findViewById(R.id.etPassword);

// if(fAuth.getCurrentUser() != null){
// startActivity(new Intent(getApplicationContext(),Startseite.class));
// finish();
// }

// btRegister.setOnClickListener(this);
login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String email = mEmail.getText().toString().trim();
String password = mPassword.getText().toString().trim();

if (TextUtils.isEmpty(email)) {
mEmail.setError("Benutzername is Required.");
return;
}

if (TextUtils.isEmpty(password)) {
mPassword.setError("Password is Required.");
return;
}



// authenticate the user

fAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Toast.makeText(MainActivity.this, "Logged in Successfully", Toast.LENGTH_SHORT).show();
startActivity(new Intent(getApplicationContext(), MainActivity.class));
} else {
Toast.makeText(MainActivity.this, "Error ! " + task.getException().getMessage(), Toast.LENGTH_SHORT).show();

}

}
});

}
});
}



}

最佳答案

您的MainActivity类不必要地实现了View.OnClickListener接口(interface)。删除 implements View.OnClickListener 即可正常工作。

关于java - 错误: MainActivity is not abstract and does not override abstract method onClick(View) in OnClickListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59690269/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com