android - 访问 Google 电子表格将在断开互联网连接后显示 nullpointerexception

android - accessing Google Spreadsheet will show nullpointerexception after the internet connection is removed

SpreadsheetService service = null;
    service = new SpreadsheetService("MySpreadsheetIntegration");
    service.setProtocolVersion(SpreadsheetService.Versions.V3);
    try {
        String urlString = "https://spreadsheets.google.com/feeds/list/1Mq_l4I6k1TMiIq6m0EFOJSqTP3aZaGgbS1CK26cZEpE/default/public/values";
        URL url = null;
        url = new URL(urlString);
        URLConnection connection = null;
        connection = url.openConnection();
        connection.setReadTimeout(30000);
        connection.setConnectTimeout(30000);
        ListFeed feed = null;
        feed = service.getFeed(url, ListFeed.class);
        for (ListEntry entry : feed.getEntries()) {
            CustomElementCollection elements = entry.getCustomElements();
        }
        return true;
    } catch (IOException e) {
        return false;
    } catch (AuthenticationException e){
        return false;
    } catch (ServiceException e) {
        return false;
    }

场景是这样的,第一次调用代码就可以了(有网络连接),然后我去掉网络,再调用这个,就报错了

它也会像这样工作,一开始没有互联网连接,我调用这个,没有错误,然后我放回互联网,再次调用这个,它会工作,然后我再次删除互联网,它会停止

这里是错误

    12-28 21:15:38.954 25196-26197/com.jintionary E/AndroidRuntime: FATAL
EXCEPTION: AsyncTask #312-28 21:15:38.954 25196-26197/com.jintionary E/AndroidRuntime: Process: com.jintionary, PID: 25196
12-28 21:15:38.954 25196-26197/com.jintionary E/AndroidRuntime: java.lang.RuntimeException: An error occured while executing doInBackground()
12-28 21:15:38.954 25196-26197/com.jintionary E/AndroidRuntime:     at android.os.AsyncTask.done(AsyncTask.java:300)
12-28 21:15:38.954 25196-26197/com.jintionary E/AndroidRuntime:     at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
12-28 21:15:38.954 25196-26197/com.jintionary E/AndroidRuntime:     at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
12-28 21:15:38.954 25196-26197/com.jintionary E/AndroidRuntime:     at java.util.concurrent.FutureTask.run(FutureTask.java:242)
12-28 21:15:38.954 25196-26197/com.jintionary E/AndroidRuntime:     at android.os.AsyncTask$SerialExecutor.run(AsyncTask.java:231)
12-28 21:15:38.954 25196-26197/com.jintionary E/AndroidRuntime:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
12-28 21:15:38.954 25196-26197/com.jintionary E/AndroidRuntime:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
12-28 21:15:38.954 25196-26197/com.jintionary E/AndroidRuntime:     at java.lang.Thread.run(Thread.java:841)
12-28 21:15:38.954 25196-26197/com.jintionary E/AndroidRuntime:  Caused by: java.lang.NullPointerException
12-28 21:15:38.954 25196-26197/com.jintionary E/AndroidRuntime:     at com.google.gdata.client.http.HttpGDataRequest.isOAuthProxyErrorResponse(HttpGDataRequest.java:566)
12-28 21:15:38.954 25196-26197/com.jintionary E/AndroidRuntime:     at com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:557)
12-28 21:15:38.954 25196-26197/com.jintionary E/AndroidRuntime:     at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:538)
12-28 21:15:38.954 25196-26197/com.jintionary E/AndroidRuntime:     at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:536)
12-28 21:15:38.954 25196-26197/com.jintionary E/AndroidRuntime:     at com.google.gdata.client.Service.getFeed(Service.java:1135)
12-28 21:15:38.954 25196-26197/com.jintionary E/AndroidRuntime:     at com.google.gdata.client.Service.getFeed(Service.java:998)
12-28 21:15:38.954 25196-26197/com.jintionary E/AndroidRuntime:     at com.google.gdata.client.GoogleService.getFeed(GoogleService.java:645)
12-28 21:15:38.954 25196-26197/com.jintionary E/AndroidRuntime:     at com.google.gdata.client.Service.getFeed(Service.java:1017)
try{
feed = service.getFeed(url, ListFeed.class);
} catch (NullPointerException e) { 
    return false;
}