Yansen Tan
Yansen Tan

Reputation: 551

Thread Exiting with Uncaught Exception in Facebook plugin for Phonegap

I'm trying to implement the facebook API plugin for Phonegap using the following plugin... https://github.com/phonegap/phonegap-facebook-plugin/issues/183

I followed the installation guide and I'm using Phonegap 2.9.0. For testing, I'm using the example provided in the project (both hackbook and also the simple one). And the app runs in Android Jelly Bean 4.2.2

But whenever I tried the login with facebook example, after tapping OK on app authentication, the android app stopped unexpectedly.

Any suggestion where should I check on?

Here is the LogCat error :

    07-21 12:25:10.568: W/dalvikvm(4288): threadid=1: thread exiting with uncaught exception (group=0x40e32930)
07-21 12:25:10.568: E/AndroidRuntime(4288): FATAL EXCEPTION: main
07-21 12:25:10.568: E/AndroidRuntime(4288): java.lang.NullPointerException
07-21 12:25:10.568: E/AndroidRuntime(4288):     at org.apache.cordova.facebook.ConnectPlugin$AuthorizeListener.onComplete(ConnectPlugin.java:283)
07-21 12:25:10.568: E/AndroidRuntime(4288):     at com.facebook.android.Facebook.onSessionCallback(Facebook.java:345)
07-21 12:25:10.568: E/AndroidRuntime(4288):     at com.facebook.android.Facebook.access$11(Facebook.java:326)
07-21 12:25:10.568: E/AndroidRuntime(4288):     at com.facebook.android.Facebook$1.call(Facebook.java:304)
07-21 12:25:10.568: E/AndroidRuntime(4288):     at com.facebook.Session$3$1.run(Session.java:1190)
07-21 12:25:10.568: E/AndroidRuntime(4288):     at android.os.Handler.handleCallback(Handler.java:725)
07-21 12:25:10.568: E/AndroidRuntime(4288):     at android.os.Handler.dispatchMessage(Handler.java:92)
07-21 12:25:10.568: E/AndroidRuntime(4288):     at android.os.Looper.loop(Looper.java:137)
07-21 12:25:10.568: E/AndroidRuntime(4288):     at android.app.ActivityThread.main(ActivityThread.java:5227)
07-21 12:25:10.568: E/AndroidRuntime(4288):     at java.lang.reflect.Method.invokeNative(Native Method)
07-21 12:25:10.568: E/AndroidRuntime(4288):     at java.lang.reflect.Method.invoke(Method.java:511)
07-21 12:25:10.568: E/AndroidRuntime(4288):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
07-21 12:25:10.568: E/AndroidRuntime(4288):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
07-21 12:25:10.568: E/AndroidRuntime(4288):     at dalvik.system.NativeStart.main(Native Method)
07-21 12:25:19.787: I/Process(4288): Sending signal. PID: 4288 SIG: 9

Upvotes: 4

Views: 550

Answers (2)

panchicore
panchicore

Reputation: 11932

complemeting to @umesh25, if using cordova 2.9 this is already patched just comment the logger that is causing a NullPointerException

277. Log.d(TAG, values.toString());

Upvotes: 2

Umesh Panchani
Umesh Panchani

Reputation: 440

In ConnectPlugin.java, replace:

try {
    JSONObject o = new JSONObject(this.fba.facebook.request("/me"));
    this.fba.userId = o.getString("id");
    this.fba.success(getResponse(), this.fba.callbackId);
} catch (MalformedURLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (JSONException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

with the following code:

Thread t = new Thread(new Runnable() {
    public void run() {
        try {
            JSONObject o = new JSONObject(fba.facebook.request("/me"));
            fba.userId = o.getString("id");
            fba.success(getResponse(), fba.callbackId);
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
});
t.start();

Ref : NetworkOnMainThreadException on Facebook Login with Phonegap 1.6.0

Upvotes: 2

Related Questions