[英]FirebaseNetworkException cannot be cast to com.google.firebase.auth.FirebaseAuthException
There is a cast problem which is FirebaseAuthException. 有一个强制转换问题是FirebaseAuthException。 In some cases, task exception cannot cast to FirebaseAuthException. 在某些情况下,任务异常无法转换为FirebaseAuthException。 How can i handle this situation? 我该如何处理这种情况? I want to try this casting process. 我想试试这个铸造过程。 If it will be success, i will show error with details to user. 如果它会成功,我将向用户显示错误详细信息。 Otherwise If it will not success, i want to show just error. 否则,如果不成功,我想表明只是错误。
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="";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.