2016-07-18 27 views
8

我有以下方法:如何擺脫Android Studio警告「不拋出getException()的結果」?

private void recoverPassword() { 

    FirebaseAuth mAuth = FirebaseAuth.getInstance();   

    mAuth.sendPasswordResetEmail("[email protected]").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中警告:

的結果 'getException()' 沒有拋出

我怎麼可以重寫代碼片段以上擺脫那個警告?

謝謝!

回答

8

添加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(或您喜歡的任何其他選項)