android - application crashes during http connection -
application crashes when try create http connection when phone connected limited wifi connection, can tell me how check internet working or not in wifi. sorry poor english.
fatal exception: main process: com.bytemachine.aditya.vehicletracker, pid: 3626 java.lang.nullpointerexception: attempt invoke interface method 'org.apache.http.httpentity org.apache.http.httpresponse.getentity()' on null object reference @ com.bytemachine.aditya.vehicletracker.searchscreen$setconnectionforvehiclesearch.onpostexecute(searchscreen.java:561) @ com.bytemachine.aditya.vehicletracker.searchscreen$setconnectionforvehiclesearch.onpostexecute(searchscreen.java:504) @ android.os.asynctask.finish(asynctask.java:636) @ android.os.asynctask.access$500(asynctask.java:177) @ android.os.asynctask$internalhandler.handlemessage(asynctask.java:653) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:145) @ android.app.activitythread.main(activitythread.java:6946) @ java.lang.reflect.method.invoke(native method) @ java.lang.reflect.method.invoke(method.java:372) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1404) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:1199)
to check network state, can use below code snippet :
connectivitymanager connectivitymanager = (connectivitymanager) context.getsystemservice(context.connectivity_service); networkinfo networkinfo = connectivitymanager.getactivenetworkinfo(); if ((networkinfo != null && networkinfo.isconnectedorconnecting())) { //network connected, carry on operations }
you can modify code checking wifi state using connectivitymanager.type_wifi flag. further details refer, https://developer.android.com/training/monitoring-device-state/connectivity-monitoring.html#determineconnection.
Comments
Post a Comment