i want to check the network state but it give me nullPointerException why?
<p>I am receiving a <code>NullPointerException</code> with the code below. Does anyone know what may be causing this?</p>

<pre><code>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();
    }
</code></pre>
