gpt4 book ai didi

java - FirebaseNetworkException 无法转换为 com.google.firebase.auth.FirebaseAuthException

转载 作者:行者123 更新时间:2023-12-02 05:09:20 24 4
gpt4 key购买 nike

存在 FirebaseAuthException 强制转换问题。在某些情况下,任务异常无法转换为 FirebaseAuthException。我该如何处理这种情况?我想尝试一下这个类型转换过程。如果成功,我将向用户显示错误及其详细信息。否则,如果它不成功,我只想显示错误。

   if(task.getException() != null){

try {
String errorCode = ((FirebaseAuthException) task.getException()).getErrorCode();

switch(errorCode) {
case "ERROR_EMAIL_ALREADY_IN_USE":
Toast.makeText(LoginActivity.this, LoginActivity.this.getResources().getString(R.string.ERROR_EMAIL_ALREADY_IN_USE),
Toast.LENGTH_SHORT).show();
stopIndicator();
break;
case "ERROR_INVALID_EMAIL":
Toast.makeText(LoginActivity.this, LoginActivity.this.getResources().getString(R.string.ERROR_INVALID_EMAIL),
Toast.LENGTH_SHORT).show();
stopIndicator();
break;
case "ERROR_WEAK_PASSWORD":
Toast.makeText(LoginActivity.this, LoginActivity.this.getResources().getString(R.string.ERROR_WEAK_PASSWORD),
Toast.LENGTH_SHORT).show();
stopIndicator();
break;
case "ERROR_CREDENTIAL_ALREADY_IN_USE":
Toast.makeText(LoginActivity.this, "CREDENTIAL ALREADY IN USE",
Toast.LENGTH_SHORT).show();
stopIndicator();
break;
default:
Toast.makeText(LoginActivity.this, LoginActivity.this.getResources().getString(R.string.Error),
Toast.LENGTH_SHORT).show();
stopIndicator();

}
}
catch (WindowManager.BadTokenException e) {
Toast.makeText(LoginActivity.this, LoginActivity.this.getResources().getString(R.string.Error),
Toast.LENGTH_SHORT).show();
stopIndicator();
}

}else{
Toast.makeText(LoginActivity.this, LoginActivity.this.getResources().getString(R.string.Error),
Toast.LENGTH_SHORT).show();
stopIndicator();
}

最佳答案

String errorCode;
if(task.getException()).getErrorCode() instanceof FirebaseAuthException){
errorCode = ((FirebaseAuthException) task.getException()).getErrorCode();

switch(errorCode) {
case "ERROR_EMAIL_ALREADY_IN_USE":
Toast.makeText(LoginActivity.this, LoginActivity.this.getResources().getString(R.string.ERROR_EMAIL_ALREADY_IN_USE),
Toast.LENGTH_SHORT).show();
stopIndicator();
break;
case "ERROR_INVALID_EMAIL":
Toast.makeText(LoginActivity.this, LoginActivity.this.getResources().getString(R.string.ERROR_INVALID_EMAIL),
Toast.LENGTH_SHORT).show();
stopIndicator();
break;
case "ERROR_WEAK_PASSWORD":
Toast.makeText(LoginActivity.this, LoginActivity.this.getResources().getString(R.string.ERROR_WEAK_PASSWORD),
Toast.LENGTH_SHORT).show();
stopIndicator();
break;
case "ERROR_CREDENTIAL_ALREADY_IN_USE":
Toast.makeText(LoginActivity.this, "CREDENTIAL ALREADY IN USE",
Toast.LENGTH_SHORT).show();
stopIndicator();
break;
default:
Toast.makeText(LoginActivity.this, LoginActivity.this.getResources().getString(R.string.Error),
Toast.LENGTH_SHORT).show();
stopIndicator();

}


}else{
errorCode="";
}

关于java - FirebaseNetworkException 无法转换为 com.google.firebase.auth.FirebaseAuthException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56333461/

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