There is a Facebook like button in my android app. But when clicking on that I got this error.
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)
Here is my code for Facebook like button
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)
This is code for like button in xml file.
<com.facebook.share.widget.LikeView
android:id="@+id/likeView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"/>
How can I solve it
Try this:
btnLike = (LikeView) findViewById(R.id.btnLike);
btnLike.setObjectIdAndType("https://www.facebook.com/androidlift", LikeView.ObjectType.PAGE);
Try to change
likeView.setObjectIdAndType(
"http://inthecheesefactory.com/blog/understand-android-activity-
launchmode/en",
LikeView.ObjectType.OPEN_GRAPH)
with
likeView.setObjectIdAndType(
"http://inthecheesefactory.com/blog/understand-android-activity-
launchmode/en",
LikeView.ObjectType.PAGE
)
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.