java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.content.Context.getApplicationContext()' on a null object reference

tip
Click on the to mark the solution that helps you, Samebug will learn from it.
As a community member, you’ll be rewarded for you help.
  1. 0

    Why can't I get context from my MainActivity in android studio?

    Stack Overflow | 6 months ago | Daniel O Mensah
    java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.content.Context.getApplicationContext()' on a null object reference

    Root Cause Analysis

    1. java.lang.NullPointerException

      Attempt to invoke virtual method 'android.content.Context android.content.Context.getApplicationContext()' on a null object reference

      at com.tramtime.owner.croydontramtime.CurrentLocation.onLocationChanged()
    2. com.tramtime.owner
      CurrentLocation.onLocationChanged
      1. com.tramtime.owner.croydontramtime.CurrentLocation.onLocationChanged(CurrentLocation.java:36)
      1 frame
    3. Android Platform
      ActivityThread.main
      1. android.location.LocationManager$ListenerTransport._handleMessage(LocationManager.java:288)
      2. android.location.LocationManager$ListenerTransport.access$000(LocationManager.java:217)
      3. android.location.LocationManager$ListenerTransport$2.handleMessage(LocationManager.java:240)
      4. android.os.Handler.dispatchMessage(Handler.java:102)
      5. android.os.Looper.loop(Looper.java:152)
      6. android.app.ActivityThread.main(ActivityThread.java:5507)
      6 frames
    4. Java RT
      Method.invoke
      1. java.lang.reflect.Method.invoke(Native Method)
      1 frame
    5. Android
      ZygoteInit.main
      1. com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
      2. com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
      2 frames