2013-10-25 77 views
0

我拋出一個異常,並像一些消息:拋出異常並獲得E無效

public static ILSResponseEmailLookUPBO getILSUserAccounts(Resources res, 
     String email) throws TripLoggerCustomException, 
     TripLoggerUnexpectedErrorException { 
    String resp = null; 

    String lookupURL; 
    try { 
     lookupURL = TripLoggerConstants.ServerConstants.ILS_LOOKUP_URL 
       + URLEncoder.encode(email, "UTF-8"); 
    } catch (UnsupportedEncodingException e1) { 
     throw new TripLoggerCustomException(
       res.getString(R.string.error_try_again)); 
    } 
    try { 
     resp = ConnectionManager.getInstance().httpRequest(lookupURL, 
       TripLoggerConstants.RequestMethods.GET); 
    } catch (IOException e) { 
     if (e.getMessage().equals(
       res.getString(R.string.network_unreachable)) 
       || e.getMessage().equals(
         res.getString(R.string.host_unresolved))) { 
      throw new TripLoggerCustomException(
        res.getString(R.string.network_not_reachable)); 
     } else { 
      throw new TripLoggerCustomException(
        res.getString(R.string.email_notfound_ils)); 
     } 
    } 

我這裏還有一部分執行。 我的異常類是:

public class TripLoggerCustomException extends Exception { 

    private String customMessage; 
    private static final long serialVersionUID = 1L; 

    public TripLoggerCustomException() { 
     super(); 
    } 

    public TripLoggerCustomException(String message) { 
     super(message); 
     this.customMessage = (message == null ? "" : message); 
    } 

    public String getCustomMessage() { 
     return this.customMessage; 
    } 

    public void setCustomMessage(String customMessage) { 
     this.customMessage = customMessage; 
    } 
    } 

這裏我捕獲這個異常:

private void manageLookUpActions(final String emailID) { 

    new Thread() { 
     public void run() { 

      try { 
       listILSAccounts = ILSLookupEmailBL.getILSUserAccounts(
         getResources(), emailID); 
      } catch (TripLoggerCustomException e) { 
       dismissProgressBar(); 
       handleException(e.getMessage()); 
       return; 
      } catch (TripLoggerUnexpectedErrorException e) { 
       dismissProgressBar(); 
       handleException(e.getMessage()); 
       return; 
      } 
} 
    }.start(); 

} 

,但在這裏的TripLoggerCustomException e美中不足的是null。爲什麼誰能幫助我?

+1

我相信這是不可能的。如果該異常爲空,那麼系統永遠不會知道它是「TripLoggerCustomException」類型。你是否在這一行中得到一個NullPointer異常:'handleException(e.getMessage());'。你可以嘗試添加一個全局'} catch(Exception e){}'來查看它是否在那裏結束? –

+0

@JeffreyKlardie沒有發生空指針異常,它完全進入TripLoggerCustomException catch塊,但問題是「e」在TripLoggerCustomException的catch塊中爲null。 – user2106897

+0

那麼,如果'e'確實爲null,則'e.getMessage()'將導致NullPointerException。我非常肯定,在這一點上,e是無效的。 –

回答

0

在StackOverflow上查看multiple reports後,看起來這不是一個實際問題。多人一直在說,這是Eclipse調試器和Android模擬器組合的問題。這就是爲什麼你不會得到一個NullPointerException,如果e爲空,你肯定會得到這個異常。

所以這可能不是你必須擔心的問題。