android - Network on main thread exception, when there's no internet -


my app works when there internet connection available. when there's no internet, gives networkonmainthreadexception. i'm using asynctask run networking code. i'm using jsoup scraping.

the logcat output given below. or tips appreciated.

05-14 23:52:47.258: e/androidruntime(21329): fatal exception: main 05-14 23:52:47.258: e/androidruntime(21329): android.os.networkonmainthreadexception 05-14 23:52:47.258: e/androidruntime(21329):    @ android.os.strictmode$androidblockguardpolicy.onnetwork(strictmode.java:1126) 05-14 23:52:47.258: e/androidruntime(21329):    @ java.net.inetaddress.lookuphostbyname(inetaddress.java:385) 05-14 23:52:47.258: e/androidruntime(21329):    @ java.net.inetaddress.getallbynameimpl(inetaddress.java:236) 05-14 23:52:47.258: e/androidruntime(21329):    @ java.net.inetaddress.getallbyname(inetaddress.java:214) 05-14 23:52:47.258: e/androidruntime(21329):    @ libcore.net.http.httpconnection.<init>(httpconnection.java:70) 05-14 23:52:47.258: e/androidruntime(21329):    @ libcore.net.http.httpconnection.<init>(httpconnection.java:50) 05-14 23:52:47.258: e/androidruntime(21329):    @ libcore.net.http.httpconnection$address.connect(httpconnection.java:340) 05-14 23:52:47.258: e/androidruntime(21329):    @ libcore.net.http.httpconnectionpool.get(httpconnectionpool.java:87) 05-14 23:52:47.258: e/androidruntime(21329):    @ libcore.net.http.httpconnection.connect(httpconnection.java:128) 05-14 23:52:47.258: e/androidruntime(21329):    @ libcore.net.http.httpengine.opensocketconnection(httpengine.java:315) 05-14 23:52:47.258: e/androidruntime(21329):    @ libcore.net.http.httpengine.connect(httpengine.java:310) 05-14 23:52:47.258: e/androidruntime(21329):    @ libcore.net.http.httpengine.sendsocketrequest(httpengine.java:289) 05-14 23:52:47.258: e/androidruntime(21329):    @ libcore.net.http.httpengine.sendrequest(httpengine.java:239) 05-14 23:52:47.258: e/androidruntime(21329):    @ libcore.net.http.httpurlconnectionimpl.connect(httpurlconnectionimpl.java:80) 05-14 23:52:47.258: e/androidruntime(21329):    @ org.jsoup.helper.httpconnection$response.execute(httpconnection.java:408) 05-14 23:52:47.258: e/androidruntime(21329):    @ org.jsoup.helper.httpconnection$response.execute(httpconnection.java:393) 05-14 23:52:47.258: e/androidruntime(21329):    @ org.jsoup.helper.httpconnection.execute(httpconnection.java:159) 05-14 23:52:47.258: e/androidruntime(21329):    @ org.jsoup.helper.httpconnection.get(httpconnection.java:148) 05-14 23:52:47.258: e/androidruntime(21329):    @ net.tuxv.mississaugabusses.data.scraper.getstops(scraper.java:60) 05-14 23:52:47.258: e/androidruntime(21329):    @ net.tuxv.mississaugabusses.data.route.scrapestops(route.java:50) 05-14 23:52:47.258: e/androidruntime(21329):    @ net.tuxv.mississaugabusses.data.route.getstops(route.java:38) 05-14 23:52:47.258: e/androidruntime(21329):    @ net.tuxv.mississaugabusses.routeactivity$scrapedatatask.onpostexecute(routeactivity.java:150) 05-14 23:52:47.258: e/androidruntime(21329):    @ net.tuxv.mississaugabusses.routeactivity$scrapedatatask.onpostexecute(routeactivity.java:130) 05-14 23:52:47.258: e/androidruntime(21329):    @ android.os.asynctask.finish(asynctask.java:631) 05-14 23:52:47.258: e/androidruntime(21329):    @ android.os.asynctask.access$600(asynctask.java:177) 05-14 23:52:47.258: e/androidruntime(21329):    @ android.os.asynctask$internalhandler.handlemessage(asynctask.java:644) 05-14 23:52:47.258: e/androidruntime(21329):    @ android.os.handler.dispatchmessage(handler.java:99) 05-14 23:52:47.258: e/androidruntime(21329):    @ android.os.looper.loop(looper.java:213) 05-14 23:52:47.258: e/androidruntime(21329):    @ android.app.activitythread.main(activitythread.java:4787) 05-14 23:52:47.258: e/androidruntime(21329):    @ java.lang.reflect.method.invokenative(native method) 05-14 23:52:47.258: e/androidruntime(21329):    @ java.lang.reflect.method.invoke(method.java:511) 05-14 23:52:47.258: e/androidruntime(21329):    @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:809) 05-14 23:52:47.258: e/androidruntime(21329):    @ com.android.internal.os.zygoteinit.main(zygoteinit.java:576) 05-14 23:52:47.258: e/androidruntime(21329):    @ dalvik.system.nativestart.main(native method) 

the stack trace says android.os.networkonmainthreadexception happening finish(). don't recognize method, possible you're doing networking in onpostexecute()?

i suspect "android.os.networkonmainthreadexception" means says.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

keyboard - C++ GetAsyncKeyState alternative -

android - java.net.UnknownHostException(Unable to resolve host “URL”: No address associated with hostname) -