title: Context.getSystemService() on a null object reference
body: <p>Whenever I try to Login in my application this <strong><code>getSystemService()</code></strong> method produce a NPE. pls. help as solutions already available are not answer to my Question. I have called <strong><code>super.oncreate()</code></strong> already. </p>
  
  <p><strong>Stack Trace</strong></p>
  
  <pre><code>Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object android.content.Context.getSystemService(java.lang.String)' on a null object reference
  at com.example.aiousecurityapplication.Utill.AppConfig.isNetworkAvailable(AppConfig.java:19)
  at com.example.aiousecurityapplication.Utill.JSONSenderReceiver.makeHttpRequest(JSONSenderReceiver.java:40)
  at com.example.aiousecurityapplication.Activities.SigninActivity$login.doInBackground(SigninActivity.java:200)
  at com.example.aiousecurityapplication.Activities.SigninActivity$login.doInBackground(SigninActivity.java:151)
  at android.os.AsyncTask$2.call(AsyncTask.java:316)
  at java.util.concurrent.FutureTask.run(FutureTask.java:237)
  at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:255) 
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) 
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) 
  at java.lang.Thread.run(Thread.java:776) 
  </code></pre>
  
  <p><strong>Method Location</strong> </p>
  
  <pre><code>public class AppConfig {
  // Server  url
  public static String URL_MAIN = "http://10.14.36.4/aiousecurity/index.php";
  public static final String FROM_CNIC = "fromCnic";
  public static final String ID = "id";
  
  public static boolean isNetworkAvailable() {
  
      boolean flag = false;
      ConnectivityManager connMgr =
              (ConnectivityManager) AIOUSecurity.getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
      if (connMgr!= null) {
          NetworkInfo networkInfo= connMgr.getActiveNetworkInfo();
          flag = (networkInfo != null &amp;&amp; networkInfo.isConnected());
      }
          return (flag);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I have also called <strong><code>super.oncreate();</code></strong> Pls. reference below code</p>
  
  <pre><code>public class AIOUSecurity extends Application {
  private static Context context;
  
  public static int screenHeight;
  public static int screenWidth;
  
  @Override
  public void onCreate() {
      super.onCreate();
      context = getApplicationContext();
  
      DisplayMetrics displayMetrics = getApplicationContext().getResources().getDisplayMetrics();
      screenHeight = displayMetrics.heightPixels;
      screenWidth = displayMetrics.widthPixels;
  }
  
  public static Context getContext() {
      return context;
  }
  </code></pre>
  
  <p>}</p>