gpt4 book ai didi

android - 不幸的是 "appname"已经停止工作

转载 作者:行者123 更新时间:2023-11-29 21:32:56 24 4
gpt4 key购买 nike

我正在关注 https://developers.facebook.com/docs/android/getting-started/facebook-sdk-for-android/对于 android sdk,一切都很顺利,因为它在给定的 lik 中有所描述,但是当我运行我的项目时,我收到错误“不幸的是‘appname’已停止工作”,这是我的 logcat 错误:

09-26 17:37:06.662: E/AndroidRuntime(5849): FATAL EXCEPTION: main
09-26 17:37:06.662: E/AndroidRuntime(5849): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.facebook.hellofriend/com.facebook.hellofriend.MainActivity}: java.lang.NullPointerException: Argument 'applicationId' cannot be null
09-26 17:37:06.662: E/AndroidRuntime(5849): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2202)
09-26 17:37:06.662: E/AndroidRuntime(5849): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2237)
09-26 17:37:06.662: E/AndroidRuntime(5849): at android.app.ActivityThread.access$600(ActivityThread.java:139)
09-26 17:37:06.662: E/AndroidRuntime(5849): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1262)
09-26 17:37:06.662: E/AndroidRuntime(5849): at android.os.Handler.dispatchMessage(Handler.java:99)
09-26 17:37:06.662: E/AndroidRuntime(5849): at android.os.Looper.loop(Looper.java:154)
09-26 17:37:06.662: E/AndroidRuntime(5849): at android.app.ActivityThread.main(ActivityThread.java:4974)
09-26 17:37:06.662: E/AndroidRuntime(5849): at java.lang.reflect.Method.invokeNative(Native Method)
09-26 17:37:06.662: E/AndroidRuntime(5849): at java.lang.reflect.Method.invoke(Method.java:511)
09-26 17:37:06.662: E/AndroidRuntime(5849): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
09-26 17:37:06.662: E/AndroidRuntime(5849): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
09-26 17:37:06.662: E/AndroidRuntime(5849): at dalvik.system.NativeStart.main(Native Method)
09-26 17:37:06.662: E/AndroidRuntime(5849): Caused by: java.lang.NullPointerException: Argument 'applicationId' cannot be null
09-26 17:37:06.662: E/AndroidRuntime(5849): at com.facebook.internal.Validate.notNull(Validate.java:29)
09-26 17:37:06.662: E/AndroidRuntime(5849): at com.facebook.Session.<init>(Session.java:227)
09-26 17:37:06.662: E/AndroidRuntime(5849): at com.facebook.Session.<init>(Session.java:216)
09-26 17:37:06.662: E/AndroidRuntime(5849): at com.facebook.Session$Builder.build(Session.java:1575)
09-26 17:37:06.662: E/AndroidRuntime(5849): at com.facebook.Session.openActiveSession(Session.java:888)
09-26 17:37:06.662: E/AndroidRuntime(5849): at com.facebook.Session.openActiveSession(Session.java:830)
09-26 17:37:06.662: E/AndroidRuntime(5849): at com.facebook.hellofriend.MainActivity.onCreate(MainActivity.java:19)
09-26 17:37:06.662: E/AndroidRuntime(5849): at android.app.Activity.performCreate(Activity.java:4538)
09-26 17:37:06.662: E/AndroidRuntime(5849): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1071)
09-26 17:37:06.662: E/AndroidRuntime(5849): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2158)
09-26 17:37:06.662: E/AndroidRuntime(5849): ... 11 more

谢谢。

我的 list 文件是:

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.facebook.hellofriend.MainActivity"
android:label="@string/app_name" >
<meta-data android:name="com.facebook.sdk.ApplicationId"
android:value="21907****928145"/>
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>

</manifest>

这是我的新 logcat 错误 :( 09-26 18:55:54.564:E/AndroidRuntime(11123):致命异常:主要09-26 18:55:54.564: E/AndroidRuntime(11123): java.lang.RuntimeException: 无法启动 Activity ComponentInfo{com.facebook.hellofriend/com.facebook.hellofriend.MainActivity}: java.lang.NullPointerException: 参数'applicationId' 不能为空09-26 18:55:54.564: E/AndroidRuntime (11123): 在 android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2202)09-26 18:55:54.564: E/AndroidRuntime (11123): 在 android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2237)09-26 18:55:54.564: E/AndroidRuntime(11123): 在 android.app.ActivityThread.access$600(ActivityThread.java:139)09-26 18:55:54.564: E/AndroidRuntime(11123): 在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1262)09-26 18:55:54.564: E/AndroidRuntime (11123): 在 android.os.Handler.dispatchMessage (Handler.java:99)09-26 18:55:54.564: E/AndroidRuntime(11123): 在 android.os.Looper.loop(Looper.java:154)09-26 18:55:54.564: E/AndroidRuntime(11123): 在 android.app.ActivityThread.main(ActivityThread.java:4974)09-26 18:55:54.564:E/AndroidRuntime(11123):在 java.lang.reflect.Method.invokeNative( native 方法)09-26 18:55:54.564: E/AndroidRuntime(11123): 在 java.lang.reflect.Method.invoke(Method.java:511)09-26 18:55:54.564: E/AndroidRuntime(11123): 在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)09-26 18:55:54.564: E/AndroidRuntime (11123): 在 com.android.internal.os.ZygoteInit.main (ZygoteInit.java:551)09-26 18:55:54.564:E/AndroidRuntime(11123):在 dalvik.system.NativeStart.main( native 方法)09-26 18:55:54.564: E/AndroidRuntime(11123): Caused by: java.lang.NullPointerException: Argument 'applicationId' cannot be null09-26 18:55:54.564: E/AndroidRuntime(11123): 在 com.facebook.internal.Validate.notNull(Validate.java:29)09-26 18:55:54.564: E/AndroidRuntime(11123): 在 com.facebook.Session.(Session.java:227)09-26 18:55:54.564: E/AndroidRuntime(11123): 在 com.facebook.Session.(Session.java:216)09-26 18:55:54.564: E/AndroidRuntime(11123): 在 com.facebook.Session$Builder.build(Session.java:1575)09-26 18:55:54.564: E/AndroidRuntime(11123): 在 com.facebook.Session.openActiveSession(Session.java:888)09-26 18:55:54.564: E/AndroidRuntime(11123): 在 com.facebook.Session.openActiveSession(Session.java:830)09-26 18:55:54.564:E/AndroidRuntime(11123):在 com.facebook.hellofriend.MainActivity.onCreate(MainActivity.java:19)09-26 18:55:54.564: E/AndroidRuntime(11123): 在 android.app.Activity.performCreate(Activity.java:4538)09-26 18:55:54.564: E/AndroidRuntime (11123): 在 android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1071)09-26 18:55:54.564: E/AndroidRuntime (11123): 在 android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2158)09-26 18:55:54.564: E/AndroidRuntime(11123): ... 11 更多

最佳答案

您必须在您的 list 文件中添加和应用程序 ID

<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/fb_app_id"/>

以上</application>标签。

"@string/fb_app_id"是来自 Facebook 开发者控制台的你的 Facebook 应用程序 ID strings.xml文件。

编辑:

如果您确定您的 list 如下所示:

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />

<uses-permission android:name="android.permission.INTERNET"/>

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.facebook.hellofriend.MainActivity"
android:label="@string/app_name" >

<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="21907****928145"/>

</application>

尝试在代码中设置 App ID:

session = new Session(this);
session = new Session.Builder(this).setApplicationId("21907****928145").build();

编辑:(在代码中使用设置应用程序 ID 的示例)

创建新类并将其放入主包中:

public class MyApp extends Application{
@Override
public void onCreate() {
super.onCreate();
session = new Session(this);
session = new Session.Builder(this).setApplicationId("21907****928145").build();
}
}

重命名您的 <application> in AndroidManifest.xml像这样:

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:name=".MyApp">
...

关于android - 不幸的是 "appname"已经停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19029102/

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