android - ConnectivityManager getActiveNetworkInfo null pointer exception -


i see null pointer exception in connectivity manager. intent service check network state isonwifi(this). exception occurs @ line cm.getactivenetworkinfo(). it's strange because check null before call this. note: permissions set.

public static boolean isonwifi(context context) {     connectivitymanager cm = (connectivitymanager) context.getsystemservice(context.connectivity_service);          return cm != null                 //here occurs nullpointerexception                 && cm.getactivenetworkinfo() != null                 && ((cm.getnetworkinfo(connectivitymanager.type_wifi) != null && cm.getnetworkinfo(                         connectivitymanager.type_wifi).isconnected()));  } 

any thoughts why happen? can't debug because it's occasional bugs reports. solution see put try catch block. thanks.

are checked api in mentioned if there no active connections returning null think ur problem.

http://developer.android.com/reference/android/net/connectivitymanager.html #getactivenetworkinfo()


Comments