I wrote the code below to check internet connection
public static boolean isNetworkAvailable(Context context) {
ConnectivityManager cm =
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
if (activeNetwork == null) {
return false;
} else {
if (activeNetwork.isConnected()) {
return true;
}
}
}
I've check if the activeNetWork is null, but still get NullPointerException error, why ?