Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

app forcecloses on starting facebook activity

I have integrated facebook sdk in my android studio project but app force closes as soon as i run the app. There is jsonexception error in designer where i have used com.facebook.login.widget.LoginButton, but it is only a designer error.

error log:

> 04-17 19:29:35.996  24734-24734/com.example.bandhan.myapplication1
> E/AndroidRuntime﹕ FATAL EXCEPTION: main
>     Process: com.example.bandhan.myapplication1, PID: 24734
>     java.lang.ExceptionInInitializerError
>             at java.lang.reflect.Constructor.newInstance(Native Method)
>             at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
>             at android.view.LayoutInflater.createView(LayoutInflater.java:614)
>             at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:750)
>             at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
>             at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
>             at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
>             at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
>             at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:435)
>             at android.app.Activity.setContentView(Activity.java:2267)
>             at com.example.bandhan.myapplication1.Share_Activity.onCreate(Share_Activity.java:15)
>             at android.app.Activity.performCreate(Activity.java:6289)
>             at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
>             at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
>             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2760)
>             at android.app.ActivityThread.access$900(ActivityThread.java:177)
>             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
>             at android.os.Handler.dispatchMessage(Handler.java:102)
>             at android.os.Looper.loop(Looper.java:145)
>             at android.app.ActivityThread.main(ActivityThread.java:5944)
>             at java.lang.reflect.Method.invoke(Native Method)
>             at java.lang.reflect.Method.invoke(Method.java:372)
>             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1389)
>             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1184)
>      Caused by: null
>             at com.facebook.internal.Validate.sdkInitialized(Validate.java:99)
>             at com.facebook.FacebookSdk.getCallbackRequestCodeOffset(FacebookSdk.java:735)
>             at com.facebook.internal.CallbackManagerImpl$RequestCodeOffset.toRequestCode(CallbackManagerImpl.java:109)
>             at com.facebook.login.widget.LoginButton.<clinit>(LoginButton.java:58)
>             at java.lang.reflect.Constructor.newInstance(Native Method)
>             at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
>             at android.view.LayoutInflater.createView(LayoutInflater.java:614)
>             at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:750)
>             at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
>             at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
>             at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
>             at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
>             at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:435)
>             at android.app.Activity.setContentView(Activity.java:2267)
>             at com.example.bandhan.myapplication1.Share_Activity.onCreate(Share_Activity.java:15)
>             at android.app.Activity.performCreate(Activity.java:6289)
>             at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
>             at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
>             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2760)
>             at android.app.ActivityThread.access$900(ActivityThread.java:177)
>             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
>             at android.os.Handler.dispatchMessage(Handler.java:102)
>             at android.os.Looper.loop(Looper.java:145)
>             at android.app.ActivityThread.main(ActivityThread.java:5944)
>             at java.lang.reflect.Method.invoke(Native Method)
>             at java.lang.reflect.Method.invoke(Method.java:372)
>             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1389)
>             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1184)

please help me to solve the problem. Thank you.

like image 350
BANDHAN MUNJAL Avatar asked Apr 17 '15 14:04

BANDHAN MUNJAL


People also ask

How do I change my activity settings on Facebook?

Tap in the top right of Facebook. Scroll down and tap Settings & Privacy, then tap Settings. Scroll down to Permissions and tap Off-Facebook activity to review. From here, you can also tap Manage Your Off-Facebook Activity for more information.

How does Facebook app know or track your activity activities on Facebook?

The tracker shows information that Facebook has gathered about your activity off the app in the past 180 days. Facebook learns that information from its advertising partnerships with third-party apps and websites, which voluntarily tell Facebook the identities of people who visit them.

How do I activate Activity Log on Facebook?

Tap in the top right of Facebook, then tap your name. Tap below your profile picture, then tap Activity Log. From here, you can tap to review activities like: Your Posts to review things like photos, videos, text and status updates you've shared on Facebook.


1 Answers

If you look at line 99 in Facebook's Validate class, you'll see it's throwing a FacebookSdkNotInitializedException

You need to call FacebookSdk.sdkInitialize(Context) before your LoginButton is loaded (i.e. your call to setContentView())

So, in your Activity's onCreate method:

public void onCreate(Bundle savedInstance){
    super.onCreate(savedInstance);
    FacebookSdk.sdkInitialize(getApplicationContext());
    setContentView(R.layout.my_layout); // Now you can set the layout with the LoginButton
}

Anytime you're going to use Facebook components, you need to ensure that the SDK is initialized.

Also make sure you have the metadata key for your Facebook Application ID in your manifest, else you're going to run into another issue when you try to actually press the LoginButton.

like image 86
Cruceo Avatar answered Nov 03 '22 00:11

Cruceo