gpt4 book ai didi

android - 应用程序在开始 Facebook Activity 时强制关闭

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:08:43 26 4
gpt4 key购买 nike

我已将 facebook sdk 集成到我的 android studio 项目中,但一旦我运行该应用程序,应用程序强制关闭。在我使用 com.facebook.login.widget.LoginButton 的设计器中存在 jsonexception 错误,但这只是设计器错误。

错误日志:

> 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)

请帮我解决这个问题。谢谢。

最佳答案

如果您查看 Facebook 的 Validate 类中的第 99 行,您会看到它抛出一个 FacebookSdkNotInitializedException

您需要在加载LoginButton 之前调用FacebookSdk.sdkInitialize(Context)(即调用setContentView())

因此,在您的ActivityonCreate 方法中:

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
}

任何时候您要使用 Facebook 组件,都需要确保 SDK 已初始化。

还要确保您的 list 中有您的 Facebook 应用程序 ID 的元数据 key ,否则当您尝试实际按下 LoginButton 时,您将遇到另一个问题。

关于android - 应用程序在开始 Facebook Activity 时强制关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29701557/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com