繁体   English   中英

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

[英]FirebaseNetworkException cannot be cast to com.google.firebase.auth.FirebaseAuthException

有一个强制转换问题是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="";
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM