title: Why can't the application launch this code?
body: <p>So I found <a href="https://stackoverflow.com/questions/6493517/android-detect-if-device-has-internet-connection">this answer</a> here. 
  But I can't get it to run since the isNetworkAvailable function isn't defined when calling it with a Context type parameter.
  This is the code I used:</p>
  
  <pre><code>private boolean isNetworkAvailable(Context context)
  {
      ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
      NetworkInfo ni = cm.getActiveNetworkInfo();
      if(ni!= null &amp;&amp; ni.isConnected())
      {
          return true;
      }
      return false;
  }
  public boolean dostupanInternet(Context context)
  {
      if(isNetworkAvailable(context))
      {
          try
          {
              HttpURLConnection url = (HttpURLConnection) (new URL("http://www.google.com").openConnection());
              url.setRequestProperty("User-Agent", "test");
              url.setRequestProperty("Connection", "close");
              url.setConnectTimeout(1000);
              url.connect();
              return(url.getResponseCode() == 200);
          }
          catch(IOException e)
          {
              Log.e("LOG_TAG","Povezivanje sa internetom nije uspelo",e);
          }
      }
      else
          {
              Log.d("LOG_TAG", "Povezivanje sa internetom nije uspelo");
          }
      return false;
  }
  </code></pre>
  
  <p>But when I run this it returns a fatal error and forces the application to shutdown.
  So my question is - what is causing the fatal error (obviously an unhandled exception) and what code would get me past that internet availability check?</p>