0
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;
    }

The scenario is like this, the first time I call it the code, it will work (with internet connection), then I remove the Internet, then I call this again, it will produce error

it will work also like this, at first with no Internet connect, I call this, no error, then I put back the internet, call this again, it will work, then I remove the internet again, it will stop

here is the error

    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$3.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$1.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)
smaxi
  • 47
  • 1
  • 6
  • Possible duplicate of [What is a Null Pointer Exception, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it) – Sufian Dec 29 '15 at 11:47

1 Answers1

0
try{
feed = service.getFeed(url, ListFeed.class);
} catch (NullPointerException e) { 
    return false;
}
Deepak John
  • 967
  • 1
  • 7
  • 19