java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.String android.content.SharedPreferences.getString(java.lang.String, java.lang.String)' on a null object reference

tip
Do you know that we can give you better hits? Get more relevant results from Samebug’s stack trace search.
  1. 0

    OkHttp Request in Separate Class

    Stack Overflow | 6 months ago | James Robert Singleton
    java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.String android.content.SharedPreferences.getString(java.lang.String, java.lang.String)' on a null object reference

    Root Cause Analysis

    1. java.lang.NullPointerException

      Attempt to invoke interface method 'java.lang.String android.content.SharedPreferences.getString(java.lang.String, java.lang.String)' on a null object reference

      at com.example.jamessingleton.chffrapi.AuthPreferences.getToken()
    2. com.example.jamessingleton
      MainActivity$1.onClick
      1. com.example.jamessingleton.chffrapi.AuthPreferences.getToken(AuthPreferences.java:43)
      2. com.example.jamessingleton.chffrapi.APIRequests.run(APIRequests.java:34)
      3. com.example.jamessingleton.chffrapi.MainActivity$1.onClick(MainActivity.java:90)
      3 frames
    3. com.google.android
      SignInButton.onClick
      1. com.google.android.gms.common.SignInButton.onClick(Unknown Source)
      1 frame
    4. Android Platform
      ActivityThread.main
      1. android.view.View.performClick(View.java:5697)
      2. android.widget.TextView.performClick(TextView.java:10814)
      3. android.view.View$PerformClick.run(View.java:22526)
      4. android.os.Handler.handleCallback(Handler.java:739)
      5. android.os.Handler.dispatchMessage(Handler.java:95)
      6. android.os.Looper.loop(Looper.java:158)
      7. android.app.ActivityThread.main(ActivityThread.java:7224)
      7 frames
    5. Java RT
      Method.invoke
      1. java.lang.reflect.Method.invoke(Native Method)
      1 frame
    6. Android
      ZygoteInit.main
      1. com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
      2. com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
      2 frames