getting a null pointer problem in the code shown here. usually a null pointer is a simple and easy thing to fix, however in this case I am totally lost on the cause.
the nullPointer is on the this line:
dataConnectionStatus = connManager.getActiveNetworkInfo().isConnected();
the code shown below is located in the beginning of the onCreate method. i used similar code earlier to check if the wifi connection is active. in this case i need to check if either the wifi or the 3g data connection is active.
the situation where it crashes with the null pointer is when both the wifi and the 3g mobile data are turned off. how to avoid the null in this situation?
ConnectivityManager connManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
boolean dataConnectionStatus = false;
if(connManager!=null){
dataConnectionStatus = connManager.getActiveNetworkInfo().isConnected(); //<-NULL
}