gpt4 book ai didi

android - 如何摆脱 Android Studio 警告 "Result of getException() not thrown"?

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:03:16 29 4
gpt4 key购买 nike

我有以下方法:

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 警告:

Result of 'getException()' not thrown

如何重写上面的代码 fragment 以消除该警告?

谢谢!

最佳答案

在方法中添加一个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'选项
  4. 点击Suppress for Method(或您喜欢的任何其他选项)

关于android - 如何摆脱 Android Studio 警告 "Result of getException() not thrown"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38427491/

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