Facebook喜欢按钮无法在Android应用程序中工作

时间:2017-05-09 09:23:56

标签: android facebook-like facebook-android-sdk

我的Android应用程序中有一个类似Facebook的按钮。但是当点击它时我得到了这个错误。

java.lang.NullPointerException: Argument 'activity' cannot be null
                  at com.facebook.internal.Validate.notNull(Validate.java:36)
                  at com.facebook.internal.FacebookDialogBase.<init>(FacebookDialogBase.java:53)
                  at com.facebook.share.internal.LikeDialog.<init>(LikeDialog.java:67)
                  at com.facebook.share.internal.LikeActionController.presentLikeDialog(LikeActionController.java:824)
                  at com.facebook.share.internal.LikeActionController.toggleLike(LikeActionController.java:698)
                  at com.facebook.share.widget.LikeView.toggleLike(LikeView.java:569)
                  at com.facebook.share.widget.LikeView.access$300(LikeView.java:52)
                  at com.facebook.share.widget.LikeView$1.onClick(LikeView.java:519)
                  at com.facebook.FacebookButtonBase$1.onClick(FacebookButtonBase.java:312)
                  at android.view.View.performClick(View.java:4496)
                  at android.view.View$PerformClick.run(View.java:18603)
                  at android.os.Handler.handleCallback(Handler.java:733)
                  at android.os.Handler.dispatchMessage(Handler.java:95)
                  at android.os.Looper.loop(Looper.java:136)
                  at android.app.ActivityThread.main(ActivityThread.java:5433)
                  at java.lang.reflect.Method.invokeNative(Native Method)
                  at java.lang.reflect.Method.invoke(Method.java:515)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
                  at dalvik.system.NativeStart.main(Native Method)

这是我的Facebook代码,如按钮

LikeView likeView = (LikeView) findViewById(R.id.likeView);
likeView.setLikeViewStyle(LikeView.Style.STANDARD);      
likeView.setAuxiliaryViewPosition(LikeView.AuxiliaryViewPosition.INLINE);
likeView.setObjectIdAndType(
    "http://inthecheesefactory.com/blog/understand-android-activity-
     launchmode/en",
      LikeView.ObjectType.OPEN_GRAPH)

这是xml文件中类似按钮的代码。

<com.facebook.share.widget.LikeView
                android:id="@+id/likeView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"/>

我该如何解决?

2 个答案:

答案 0 :(得分:0)

试试这个:

btnLike = (LikeView) findViewById(R.id.btnLike);
btnLike.setObjectIdAndType("https://www.facebook.com/androidlift", LikeView.ObjectType.PAGE);

答案 1 :(得分:0)

尝试更改

likeView.setObjectIdAndType(
"http://inthecheesefactory.com/blog/understand-android-activity-
 launchmode/en",
  LikeView.ObjectType.OPEN_GRAPH)

likeView.setObjectIdAndType(
"http://inthecheesefactory.com/blog/understand-android-activity-
 launchmode/en",
  LikeView.ObjectType.PAGE