android - nullpointer exception on connectivitymanager -
public boolean isonline() { connectivitymanager cm = (connectivitymanager) getsystemservice(context.connectivity_service); return cm.getactivenetworkinfo().isconnectedorconnecting();}
i'm getting nullpointer on return cm.getactivenetworkinfo
.
i tried this.getsystemservice
didn't work. maybe because activity extends super activity i've created , i'm grabbing context incorrectly...? tried getbasecontext()
too
with 2 methods chained on return line, sure it's connectivitymanager
coming null? it's valid connectivitymanager.getactivenetworkinfo()
return null
instead of valid networkinfo
object when there no active network. if comes null
, call networkinfo.isconnectedorconnecting()
throwing exception.
Comments
Post a Comment