PokeGOAPI-Java
PokeGOAPI-Java copied to clipboard
OnGoogleLoginOAuthCompleteListener.onInitialOAuthComplete on a null reference
When i try to login with google it show me the error my code is
GoogleAuthJson authJson = new GoogleAuthJson();
GoogleAuthTokenJson tokenJson = new GoogleAuthTokenJson();
listener.onInitialOAuthComplete(authJson);
listener.onTokenIdReceived(tokenJson);
auth = new GoogleCredentialProvider(http,listener);
go = new PokemonGo(auth, http);
and stack trace is
FATAL EXCEPTION: main
Process: com.example.app, PID: 30084
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.app/com.example.app.LoginActivity}: java.lang.NullPointerException: Attempt to invoke interface method 'void com.pokegoapi.auth.GoogleCredentialProvider$OnGoogleLoginOAuthCompleteListener.onInitialOAuthComplete(com.pokegoapi.auth.GoogleAuthJson)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.access$900(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'void com.pokegoapi.auth.GoogleCredentialProvider$OnGoogleLoginOAuthCompleteListener.onInitialOAuthComplete(com.pokegoapi.auth.GoogleAuthJson)' on a null object reference
at com.example.app.LoginActivity.onCreate(LoginActivity.java:72)
at android.app.Activity.performCreate(Activity.java:6285)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.access$900(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
what am i supposed to do.
what about this:
You're running the sample code on the UI thread. Strict mode policy will throw an exception in that case and its being caught by the network client and treating it as a login failed exception. Run the sample code on a background thread in AsyncTask or RXJava and it will work.
You are not supposed to use the GoogleLoginProvider like this, more like this. You should learn what is an interface in Java.
thans for advice