如何摆脱Android Studio警告"未抛出getException()的结果"?

时间:2016-07-18 01:32:32

标签: android android-studio firebase firebase-authentication

我有以下方法:

private void recoverPassword() {

    FirebaseAuth mAuth = FirebaseAuth.getInstance();        

    mAuth.sendPasswordResetEmail("mail@example.com").addOnCompleteListener(new OnCompleteListener<Void>() {

        @Override
        public void onComplete(@NonNull Task<Void> task) {
            if (!task.isSuccessful()) {
                Exception e = task.getException();
                System.out.println(e.toString());
        }
    });

}

我一直收到Android Studio警告:

  

&#39; getException()&#39;的结果没有抛出

如何重写上面的代码片段以消除警告?

谢谢!

1 个答案:

答案 0 :(得分:10)

在方法中添加SuppressWarnings注释:

        @SuppressWarnings("ThrowableResultOfMethodCallIgnored")
        @Override
        public void onComplete(@NonNull Task<Void> task) {
            if (!task.isSuccessful()) {
                Exception e = task.getException();
                System.out.println(e.toString());
            }
        }

Android Studio将为您提供帮助:

  1. 将光标放在getException()
  2. 输入Alt-Enter
  3. 点击Inspection 'Throwable result of method call ignored' options
  4. 点击Suppress for Method(或您喜欢的任何其他选项)
相关问题