我收到了NullPointerException
下面的代码。有谁知道可能是什么原因造成的?
public void clickMe(View v) //the view is button
{
ConnectivityManager conMgr = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = conMgr.getActiveNetworkInfo();
String b;
if(networkInfo.isConnected())
b="on";
else
b="off";
Toast.makeText(MainActivity.this, b , Toast.LENGTH_SHORT).show();
}