我正在尝试使用以下插件为Phonegap实现facebook API插件... https://github.com/phonegap/phonegap-facebook-plugin/issues/183
我按照安装指南操作,我使用的是Phonegap 2.9.0。为了测试,我使用的是项目中提供的示例(hackbook和简单版本)。该应用程序在Android Jelly Bean 4.2.2中运行
但每当我尝试使用facebook示例登录时,点击应用认证后确定,Android应用程序意外停止。
有任何建议我应该在哪里检查?
这是LogCat错误:
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
答案 0 :(得分:2)
在ConnectPlugin.java中,替换:
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();
}
使用以下代码:
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();
参考:NetworkOnMainThreadException on Facebook Login with Phonegap 1.6.0
答案 1 :(得分:2)
补充@ umesh25,如果使用cordova 2.9这已经修补,只需注释导致NullPointerException
的记录器
277. Log.d(TAG, values.toString());