title: Attempt to invoke virtual method 'android.content.pm.PackageManager android.content.Context.getPackageManager()' on a null object reference
body: <pre><code>Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.pm.PackageManager android.content.Context.getPackageManager()' on a null object reference
  </code></pre>
  
  <p>This is the error I am getting even though I have never used <strong><code>getPackageManager()</code></strong> method.</p>
  
  <p>Following is my code:</p>
  
  <p>AppUtils.java :</p>
  
  <pre><code>public static boolean checkPlayServices() {
  
      int resultCode = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(mContext);
  
      if (resultCode != ConnectionResult.SUCCESS) {
          if (GoogleApiAvailability.getInstance().isUserResolvableError(resultCode)) {
              GoogleApiAvailability.getInstance().getErrorDialog((Activity) mContext, resultCode, PLAY_SERVICES_RESOLUTION_REQUEST);
          } else {
              Toast.makeText(mContext, "This Device is not Supported!", Toast.LENGTH_LONG).show();
          }
          return false;
      }
      return true;
  }
  </code></pre>
  
  <p>MyUtils.java :</p>
  
  <pre><code>@Override
  protected void onResume() {
      super.onResume();
      utils.checkPlayServices();
  }
  </code></pre>
  
  <p>Log cat error:</p>
  
  <pre><code>11-18 12:32:07.705 21076-21076/com.vtrak E/AndroidRuntime: FATAL EXCEPTION: main
                                                         Process: com.vtrak, PID: 21076
                                                         java.lang.RuntimeException: Unable to resume activity {com.vtrak/com.vtrak.Activities.HomeActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.pm.PackageManager android.content.Context.getPackageManager()' on a null object reference
                                                             at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3334)
                                                             at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3365)
                                                             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2690)
                                                             at android.app.ActivityThread.access$900(ActivityThread.java:188)
                                                             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1530)
                                                             at android.os.Handler.dispatchMessage(Handler.java:111)
                                                             at android.os.Looper.loop(Looper.java:210)
                                                             at android.app.ActivityThread.main(ActivityThread.java:5839)
                                                             at java.lang.reflect.Method.invoke(Native Method)
                                                             at java.lang.reflect.Method.invoke(Method.java:372)
                                                             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1113)
                                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:879)
                                                          Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.pm.PackageManager android.content.Context.getPackageManager()' on a null object reference
                                                             at com.google.android.gms.common.zze.isGooglePlayServicesAvailable(Unknown Source)
                                                             at com.google.android.gms.common.zzc.isGooglePlayServicesAvailable(Unknown Source)
                                                             at com.google.android.gms.common.GoogleApiAvailability.isGooglePlayServicesAvailable(Unknown Source)
                                                             at com.vtrak.Classes.Utils.checkPlayServices(Utils.java:92)
                                                             at com.vtrak.Activities.HomeActivity.onResume(HomeActivity.java:66)
                                                             at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1267)
                                                             at android.app.Activity.performResume(Activity.java:6263)
                                                             at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3319)
                                                             at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3365) 
                                                             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2690) 
                                                             at android.app.ActivityThread.access$900(ActivityThread.java:188) 
                                                             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1530) 
                                                             at android.os.Handler.dispatchMessage(Handler.java:111) 
                                                             at android.os.Looper.loop(Looper.java:210) 
                                                             at android.app.ActivityThread.main(ActivityThread.java:5839) 
                                                             at java.lang.reflect.Method.invoke(Native Method) 
                                                             at java.lang.reflect.Method.invoke(Method.java:372) 
                                                             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1113) 
                                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:879) 
  </code></pre>
  
  <p>I get this error when this method is called, I don't understand why my app is crashing this method has nothing to do with checkplayServices() method :</p>
  
  <pre><code>private void getHistory() {
      /*String assetNo = null;
      Bundle bun = getIntent().getExtras();
      if (bun != null) {
  
          assetNo = bun.getString(RecyclerAdapter.KEY_VEH_NUM, null);
      }*/
      String startDate = tvDate.getText() + " " + tvStartTime.getText();
      String endDate = tvDate.getText() + " " + tvEndTime.getText();
  
  
      Call&lt;ModelHistory&gt; call = Utils.retroInterface.getHistory("SG00iX", "Android", Integer.parseInt(LogInActivity.sharedPreferences.getString(LogInActivity.KEY_RESULT_MSG, null)), "GBE8185Y", startDate, endDate);
  
      call.enqueue(new Callback&lt;ModelHistory&gt;() {
          @Override
          public void onResponse(Call&lt;ModelHistory&gt; call, Response&lt;ModelHistory&gt; response) {
  
              for (int i = 0; i &lt; response.body().getData().size(); i++) {
  
  
                  Log.i("lat long : ", response.body().getData().get(i).getLocLat() + "   " + response.body().getData().get(i).getLocLon());
  
                  listLat.add(Double.valueOf(response.body().getData().get(i).getLocLat()));
                  listLat.add(Double.valueOf(response.body().getData().get(i).getLocLon()));
  
              }
  
              showInMap(listLat, listLong);
  
          }
  
          @Override
          public void onFailure(Call&lt;ModelHistory&gt; call, Throwable t) {
              Log.i("no, ", "its failure" + t.toString());
          }
      });
  }
  </code></pre>
  
  <p><strong><em>Edit:</em></strong><br>
  Got the answer finally, lists were not initialized, initializing them like this, solved problem:</p>
  
  <pre><code>listLat = new ArrayList&lt;Double&gt;;
  listLon = new ArrayList&lt;Double&gt;;
  </code></pre>