简体   繁体   中英

Why is this handled exception causing a Force Close? [GeoCoder]

I have the following in my AsyncTask:

@Override
protected Void doInBackground(Context... c) {

    try {
        context = c[0];

        myLocation = new Geocoder((Activity)context, Locale.getDefault()); 

        if(myLocation.isPresent())
            myList = myLocation.getFromLocation(LocationHandler.getLat(), LocationHandler.getLon(), 1);
    } 
    catch (IOException e) 
    {
        e.printStackTrace();
    }
    catch (Exception e) 
    {
        e.printStackTrace();
    }

    return null;
}

If I run this AsyncTask with no network connection, my application will Force Close with the following stack output:

 java.io.IOException: Unable to parse response from server
 at android.location.Geocoder.getFromLocation(Geocoder.java:136)
 at com.soyo.winnipegtransit.location.UpdateGeoCoderName.doInBackground(UpdateGeoCoderName.java:44)
 at com.soyo.winnipegtransit.location.UpdateGeoCoderName.doInBackground(UpdateGeoCoderName.java:1)
 at android.os.AsyncTask$2.call(AsyncTask.java:185)
 at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
 at java.util.concurrent.FutureTask.run(FutureTask.java:138)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
 at java.lang.Thread.run(Thread.java:1019)

I'm not sure why this exception is going unhandled?

I've had similar problems with exceptions not being handled. It usually got solved by just handling the exception with one catch statement, don't ask me how but I'm sure there's a good reason behind this. Have you tried removing the catch(IOException e) and just keeping catch(Exception e) ?

Ryan

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM