gdx-facebook
gdx-facebook copied to clipboard
Android: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
Awesome job on this library! I managed to get it work on Desktop, but on Android I'm getting a NullPointerException.
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
at com.facebook.login.LoginClient.getLogger(LoginClient.java:373)
in com.facebook.login.LoginClient.getLogger
pendingRequest.getApplicationId()
seems to be null.
The code I'm using:
Gdx.app.setLogLevel(Application.LOG_DEBUG);
GDXFacebookConfig config = new GDXFacebookConfig();
config.APP_ID = "replaced-this-with-actual-app-id"; // required
config.PREF_FILENAME = ".facebookSessionData"; // optional
config.GRAPH_API_VERSION = "v2.6"; // optional, default is v2.6
GDXFacebook facebook = GDXFacebookSystem.install(config);
Array<String> permissions = new Array<String>();
permissions.add("email");
permissions.add("public_profile");
permissions.add("user_friends");
facebook.signIn(SignInMode.READ, permissions, new GDXFacebookCallback<SignInResult>() {
@Override
public void onSuccess(SignInResult result) {
// Login successful
}
@Override
public void onError(GDXFacebookError error) {
// Error handling
}
@Override
public void onCancel() {
// When the user cancels the login process
}
@Override
public void onFail(Throwable t) {
// When the login fails
}
});
Did I miss something
Full stack trace:
D/gdx-facebook (1.4.1): gdx-facebook (1.4.1) for Android installed successfully.
D/gdx-facebook (1.4.1): Could not load existing accessToken.
D/gdx-facebook (1.4.1): Starting GUI sign in.
I/OMXClient: IOmx service obtained
I/BaseScreen: Disposing.
I/AndroidInput: sensor listener tear down
I/AndroidGraphics: paused
W/com.facebook.appevents.internal.ActivityLifecycleTracker: Unexpected activity pause without a matching activity resume. Logging data may be incorrect. Make sure you call activateApp from your Application's onCreate method
W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@563aa9d
I/OMXClient: IOmx service obtained
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.ph.myapp, PID: 9529
java.lang.RuntimeException: Unable to resume activity {com.ph.myapp/com.facebook.FacebookActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3784)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3816)
at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:51)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:145)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
at com.facebook.login.LoginClient.getLogger(LoginClient.java:373)
at com.facebook.login.LoginClient.tryCurrentHandler(LoginClient.java:261)
at com.facebook.login.LoginClient.tryNextHandler(LoginClient.java:216)
at com.facebook.login.LoginClient.authorize(LoginClient.java:121)
at com.facebook.login.LoginClient.startOrContinueAuth(LoginClient.java:102)
at com.facebook.login.LoginFragment.onResume(LoginFragment.java:153)
at android.support.v4.app.Fragment.performResume(Fragment.java:2133)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1156)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1295)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1277)
at android.support.v4.app.FragmentManagerImpl.dispatchResume(FragmentManager.java:2164)
at android.support.v4.app.FragmentController.dispatchResume(FragmentController.java:223)
at android.support.v4.app.FragmentActivity.onResumeFragments(FragmentActivity.java:509)
at android.support.v4.app.FragmentActivity.onPostResume(FragmentActivity.java:498)
at android.app.Activity.performResume(Activity.java:7317)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3776)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3816)
at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:51)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:145)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
I/Process: Sending signal. PID: 9529 SIG: 9
Application terminated.
Am I doing something wrong?
After some good old debugging, seems to work fine after I add:
FacebookSdk.setApplicationId(getString(R.string.facebook_app_id));
in my class AndroidLauncher extends com.badlogic.gdx.backends.android.AndroidApplication
Shouldn't FacebookSdk.setApplicationId
be performed by the gdx-facebook
library or by the facebook android library itself?
Or should we add this to the wiki.
Perhaps I'm missing something here... :D
No idea what might be wrong. Did you add the app id to the AndroidManifest.xml?
If you provide a working project example I can look further into it.