简体   繁体   中英

Facebook SDK doesn't work after API LEVEL 10 on Android

I used Facebook SDK (and Twitter, Linkedin) to make a log in on my app. It works perfectly if I specify the minSdkVersion<10. I need to upgrade the app to use Fragment..

<uses-sdk android:minSdkVersion="10" />

For the 11 and greater, the app crashes after receiving the token! I need help! Take a look at the error:

UPDATE

07-12 16:58:44.136: D/AndroidRuntime(18310): Shutting down VM

    07-12 16:58:44.148: E/AndroidRuntime(18310): FATAL EXCEPTION: main
07-12 16:58:44.148: E/AndroidRuntime(18310): java.lang.NullPointerException: println needs a message
07-12 16:58:44.148: E/AndroidRuntime(18310):    at android.util.Log.println_native(Native Method)
07-12 16:58:44.148: E/AndroidRuntime(18310):    at android.util.Log.d(Log.java:138)
07-12 16:58:44.148: E/AndroidRuntime(18310):    at com.branchu1.Login$1$1.onComplete(Login.java:161)
07-12 16:58:44.148: E/AndroidRuntime(18310):    at com.facebook.android.Facebook$1.onComplete(Facebook.java:312)
07-12 16:58:44.148: E/AndroidRuntime(18310):    at com.facebook.android.FbDialog$FbWebViewClient.shouldOverrideUrlLoading(FbDialog.java:144)
07-12 16:58:44.148: E/AndroidRuntime(18310):    at android.webkit.CallbackProxy.uiOverrideUrlLoading(CallbackProxy.java:224)
07-12 16:58:44.148: E/AndroidRuntime(18310):    at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:324)
07-12 16:58:44.148: E/AndroidRuntime(18310):    at android.os.Handler.dispatchMessage(Handler.java:99)
07-12 16:58:44.148: E/AndroidRuntime(18310):    at android.os.Looper.loop(Looper.java:137)
07-12 16:58:44.148: E/AndroidRuntime(18310):    at android.app.ActivityThread.main(ActivityThread.java:4424)
07-12 16:58:44.148: E/AndroidRuntime(18310):    at java.lang.reflect.Method.invokeNative(Native Method)
07-12 16:58:44.148: E/AndroidRuntime(18310):    at java.lang.reflect.Method.invoke(Method.java:511)
07-12 16:58:44.148: E/AndroidRuntime(18310):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-12 16:58:44.148: E/AndroidRuntime(18310):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-12 16:58:44.148: E/AndroidRuntime(18310):    at dalvik.system.NativeStart.main(Native Method)

It's exactly the same thing with the Twitter and Linkedin SDK. And if I remove the field android:minSdkVersion from the manifest, it works. I really don't understand!

Thanks!

"@Rawkode Line 161 is a lof of the facebook sdk. Log.d("Facebook", e.getMessage()); It seems, Facebook didn't send anything and I get an error from this line."

Your issue is that e.getMessage() is a null String, and when you try to call Log.d(TAG, message) with a null String, it will crash with an NPE. I experienced similar issues and it took me a while to track it down:

Some errors do not have any data for the getMessage() method, as it's not required. My solution was to create my own method that always has some text in it, and you'll never get another NPE from that again:

private void logIt(String message){
    Log.d(TAG, "Logged: " + message);
}

Just call that instead of the normal Log.d() and you won't get that issue as there will ALWAYS be data to log (and in your case, it will say: "Logged: null"). You can also modify that method to accept individual tags, but isn't necessary.

I have the same error.. The app works perfectly on versión 9 or below, but with the android 3.0 or higher doesn't work.

Try with the new facebook's api, it works..

https://developers.facebook.com/android/

Sorry for my english!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM