###質問
Android アプリで Facebook loginを実行しようとしたところ、実機で実行後すぐに落ちてしまいます。
24行目の getApplicationContext()と、AppEventsLogger でエラーNullPointerになります。
この関数の直前の sdkInitializeとctivateAppが棒線で消されていますが、他の関数を使う必要があるのでしょうか?
どのように変更すればいいかアドバイスをいただきたいです。
###rinjintoさんへの返信
SDKは、11.0がinstallされており、私の使っている実機(スマホ)もAndroid Versionが11です。
また Tool bar -> SDK Manager ->SDK Tools の中で、Android SDK Platform-Toolsと、SDK Build-Tools をupdateしたのですが、エラーは消えませんでした。
下記の画像はSDK Toolsの中のインストール状況です。
本来は下記の画像のように、Continue with Facebookボタンが表示されるはずなのですが、
AppEventsLogger.activateApp(this);を消して、this.getApplicationContext();を代わりに追加した後に、Null Pointerは消えたものの、画像のようなページが表示されません。
###hoshi-takanoriさんへの返信
指摘がありましたmanifestファイルです。
manifest.xml
1<?xml version="1.0" encoding="utf-8"?> 2<manifest xmlns:android="http://schemas.android.com/apk/res/android" 3 package="com.example.rutgersoffcampushousing"> 4 5 <application 6 android:allowBackup="true" 7 android:icon="@mipmap/ic_launcher" 8 android:label="@string/app_name" 9 android:roundIcon="@mipmap/ic_launcher_round" 10 android:supportsRtl="true" 11 android:theme="@style/Theme.RutgersOffCampusHousing"> 12 <activity android:name=".MainActivity"> 13 <intent-filter> 14 <action android:name="android.intent.action.MAIN" /> 15 16 <category android:name="android.intent.category.LAUNCHER" /> 17 </intent-filter> 18 </activity> 19 20 <meta-data android:name="com.facebook.sdk.ApplicationId" 21 android:value="@string/facebook_app_id"/> 22 23 <activity android:name="com.facebook.FacebookActivity" 24 android:configChanges= 25 "keyboard|keyboardHidden|screenLayout|screenSize|orientation" 26 android:label="@string/app_name" /> 27 <activity 28 android:name="com.facebook.CustomTabActivity" 29 android:exported="true"> 30 <intent-filter> 31 <action android:name="android.intent.action.VIEW" /> 32 <category android:name="android.intent.category.DEFAULT" /> 33 <category android:name="android.intent.category.BROWSABLE" /> 34 <data android:scheme="@string/fb_login_protocol_scheme" /> 35 </intent-filter> 36 </activity> 37 38 </application> 39 40 <uses-permission android:name="android.permission.INTERNET"/> 41 42 43</manifest>
###エラーコード
error
1 205/10 18:51:52: Launching 'app' on Google Pixel 3a. 3Install successfully finished in 729 ms. 4$ adb shell am start -n "com.example.rutgersoffcampushousing/com.example.rutgersoffcampushousing.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER 5Connected to process 15844 on device 'google-pixel_3a-02SAY1UHPZ'. 6Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page. 7I/ffcampushousin: Late-enabling -Xcheck:jni 8I/ffcampushousin: Unquickening 12 vdex files! 9D/NetworkSecurityConfig: No Network Security Config specified, using platform default 10D/NetworkSecurityConfig: No Network Security Config specified, using platform default 11W/com.facebook.UserSettingsManager: Please set a value for AutoLogAppEventsEnabled. Set the flag to TRUE if you want to collect app install, app launch and in-app purchase events automatically. To request user consent before collecting data, set the flag value to FALSE, then change to TRUE once user consent is received. Learn more: https://developers.facebook.com/docs/app-events/getting-started-app-events-android#disable-auto-events. 12 You haven't set a value for AdvertiserIDCollectionEnabled. Set the flag to TRUE if you want to collect Advertiser ID for better advertising and analytics results. To request user consent before collecting data, set the flag value to FALSE, then change to TRUE once user consent is received. Learn more: https://developers.facebook.com/docs/app-events/getting-started-app-events-android#disable-auto-events. 13D/AndroidRuntime: Shutting down VM 14E/AndroidRuntime: FATAL EXCEPTION: main 15 Process: com.example.rutgersoffcampushousing, PID: 15844 16 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.rutgersoffcampushousing/com.example.rutgersoffcampushousing.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.content.Context.getApplicationContext()' on a null object reference 17 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3431) 18 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3595) 19 at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 20 at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 21 at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 22 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 23 at android.os.Handler.dispatchMessage(Handler.java:106) 24 at android.os.Looper.loop(Looper.java:223) 25 at android.app.ActivityThread.main(ActivityThread.java:7660) 26 at java.lang.reflect.Method.invoke(Native Method) 27 at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 28 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 29 Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.content.Context.getApplicationContext()' on a null object reference 30 at com.facebook.FacebookSdk.publishInstallAsync(FacebookSdk.java:644) 31 at com.facebook.appevents.AppEventsLoggerImpl.activateApp(AppEventsLoggerImpl.java:114) 32 at com.facebook.appevents.AppEventsLogger.activateApp(AppEventsLogger.java:200) 33 at com.facebook.appevents.AppEventsLogger.activateApp(AppEventsLogger.java:209) 34 at com.example.rutgersoffcampushousing.MainActivity.onCreate(MainActivity.java:25) 35 at android.app.Activity.performCreate(Activity.java:8000) 36 at android.app.Activity.performCreate(Activity.java:7984) 37 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309) 38 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3404) 39 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3595) 40 at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 41 at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 42 at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 43 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 44 at android.os.Handler.dispatchMessage(Handler.java:106) 45 at android.os.Looper.loop(Looper.java:223) 46 at android.app.ActivityThread.main(ActivityThread.java:7660) 47 at java.lang.reflect.Method.invoke(Native Method) 48 at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 49 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
回答1件
あなたの回答
tips
プレビュー