gpt4 book ai didi

java - applicationId 不能为空,但 xml 语法正确

转载 作者:数据小太阳 更新时间:2023-10-29 02:30:30 25 4
gpt4 key购买 nike

我正在尝试将 Facebook 添加到已经完成的 LibGDX 游戏中。但是,当我尝试检查当前 session 时,它返回 null。我试图创建一个新的 Session 来代替,但我得到了一个空指针错误:

01-04 19:49:15.433: E/AndroidRuntime(16540): FATAL EXCEPTION: main
01-04 19:49:15.433: E/AndroidRuntime(16540): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pressx.thedevice/com.pressx.thedevice.MainActivity}: java.lang.NullPointerException: Argument 'applicationId' cannot be null
01-04 19:49:15.433: E/AndroidRuntime(16540): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2070)
01-04 19:49:15.433: E/AndroidRuntime(16540): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2095)
01-04 19:49:15.433: E/AndroidRuntime(16540): at android.app.ActivityThread.access$600(ActivityThread.java:135)
01-04 19:49:15.433: E/AndroidRuntime(16540): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1201)
01-04 19:49:15.433: E/AndroidRuntime(16540): at android.os.Handler.dispatchMessage(Handler.java:99)
01-04 19:49:15.433: E/AndroidRuntime(16540): at android.os.Looper.loop(Looper.java:137)
01-04 19:49:15.433: E/AndroidRuntime(16540): at android.app.ActivityThread.main(ActivityThread.java:4849)
01-04 19:49:15.433: E/AndroidRuntime(16540): at java.lang.reflect.Method.invokeNative(Native Method)
01-04 19:49:15.433: E/AndroidRuntime(16540): at java.lang.reflect.Method.invoke(Method.java:511)
01-04 19:49:15.433: E/AndroidRuntime(16540): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
01-04 19:49:15.433: E/AndroidRuntime(16540): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
01-04 19:49:15.433: E/AndroidRuntime(16540): at dalvik.system.NativeStart.main(Native Method)
01-04 19:49:15.433: E/AndroidRuntime(16540): Caused by: java.lang.NullPointerException: Argument 'applicationId' cannot be null
01-04 19:49:15.433: E/AndroidRuntime(16540): at com.facebook.internal.Validate.notNull(Validate.java:29)
01-04 19:49:15.433: E/AndroidRuntime(16540): at com.facebook.Session.<init>(Session.java:227)
01-04 19:49:15.433: E/AndroidRuntime(16540): at com.facebook.Session.<init>(Session.java:216)
01-04 19:49:15.433: E/AndroidRuntime(16540): at com.facebook.Session$Builder.build(Session.java:1576)
01-04 19:49:15.433: E/AndroidRuntime(16540): at com.facebook.Session.openActiveSession(Session.java:888)
01-04 19:49:15.433: E/AndroidRuntime(16540): at com.facebook.Session.openActiveSession(Session.java:830)
01-04 19:49:15.433: E/AndroidRuntime(16540): at com.pressx.facebook.FacebookAndroid.<init>(FacebookAndroid.java:27)
01-04 19:49:15.433: E/AndroidRuntime(16540): at com.pressx.thedevice.MainActivity.onCreate(MainActivity.java:17)
01-04 19:49:15.433: E/AndroidRuntime(16540): at android.app.Activity.performCreate(Activity.java:5244)
01-04 19:49:15.433: E/AndroidRuntime(16540): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1082)
01-04 19:49:15.433: E/AndroidRuntime(16540): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2034)
01-04 19:49:15.433: E/AndroidRuntime(16540): ... 11 more

如果 Facebook 检查 AndroidManifest.xml 中的 ApplicationID 值,那么正确的语法是什么?我有这个作为我的元数据行:

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

以此作为我的值字符串:

<string name="app_id">###############</string>

目前完整的 AndroidManifest.xml 如下所示:

<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.pressx.thedevice" android:versionCode="1" android:versionName="1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-sdk android:minSdkVersion="11" android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET"/>
<application android:icon="@drawable/ic_launcher" android:label="@string/app_name" >
<meta-data android:name="ApplicationId" android:value="@string/app_id"/>
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id" />
<activity android:name="com.facebook.LoginActivity">
</activity>
<activity android:name=".MainActivity" android:label="@string/app_name" android:screenOrientation="landscape" android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

我的完整 values.xml 如下所示:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">The Device</string>
<string name="app_id">###############</string>
</resources>

谁有办法解决这个问题?您是否需要更多信息,例如我的项目设置或类似信息?

最佳答案

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

必须在 <application /> 中声明范围,而不是 <activity />范围。将标签移到 Activity 外部,如下所示:

<application android:icon="@drawable/ic_launcher" android:label="@string/app_name" >
<!-- Note new location -->
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id" />
<meta-data android:name="ApplicationId" android:value="@string/app_id"/>
<activity android:name="com.facebook.LoginActivity"></activity>
<activity android:name=".MainActivity" android:label="@string/app_name" android:screenOrientation="landscape" android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

关于java - applicationId 不能为空,但 xml 语法正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20929925/

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