Question

I am running Facebook Ad for Mobile Install, that's why i added Facebook sdk to my app to track installs, And added code as per instructions. But Now i am getting force close, also i checked in all new and old android versions. when i comment the code all working fine.

Here is code what i added:-

...
@Override
    protected void onResume() {
        super.onResume();
        if (adView != null) {
            adView.resume();
        }

            //Below Code which i added.
        com.facebook.AppEventsLogger.activateApp(context, "263969900451122");
    }

...

All Working fine but when i add this code as per instructed to add in onResume, app is force closing :

com.facebook.AppEventsLogger.activateApp(context, "263969900451122");


As per Requested log cat:-

04-07 04:04:54.591: D/dalvikvm(345): DexOpt: couldn't find field Landroid/content/res/Configuration;.smallestScreenWidthDp
04-07 04:04:54.591: W/dalvikvm(345): VFY: unable to resolve instance field 48
04-07 04:04:54.591: D/dalvikvm(345): VFY: replacing opcode 0x52 at 0x0012
04-07 04:04:54.591: D/dalvikvm(345): VFY: dead code 0x0014-0018 in Lcom/google/android/gms/common/GooglePlayServicesUtil;.b (Landroid/content/res/Resources;)Z
04-07 04:04:54.621: I/dalvikvm(345): Could not find method android.app.Activity.getFragmentManager, referenced from method com.google.android.gms.common.GooglePlayServicesUtil.showErrorDialogFragment
04-07 04:04:54.621: W/dalvikvm(345): VFY: unable to resolve virtual method 21: Landroid/app/Activity;.getFragmentManager ()Landroid/app/FragmentManager;
04-07 04:04:54.621: D/dalvikvm(345): VFY: replacing opcode 0x6e at 0x0023
04-07 04:04:54.631: D/dalvikvm(345): VFY: dead code 0x0026-0030 in Lcom/google/android/gms/common/GooglePlayServicesUtil;.showErrorDialogFragment (ILandroid/app/Activity;ILandroid/content/DialogInterface$OnCancelListener;)Z
04-07 04:04:54.661: W/GooglePlayServicesUtil(345): Google Play services is missing.
04-07 04:04:54.681: I/dalvikvm(345): Could not find method java.io.IOException.<init>, referenced from method com.google.android.gms.internal.k.f
04-07 04:04:54.681: W/dalvikvm(345): VFY: unable to resolve direct method 28279: Ljava/io/IOException;.<init> (Ljava/lang/Throwable;)V
04-07 04:04:54.681: D/dalvikvm(345): VFY: replacing opcode 0x70 at 0x0050
04-07 04:04:54.691: D/dalvikvm(345): VFY: dead code 0x0053-0053 in Lcom/google/android/gms/internal/k;.f (Landroid/content/Context;)Lcom/google/android/gms/internal/k$a;
04-07 04:04:54.961: D/dalvikvm(345): DexOpt: --- BEGIN 'ads18470.jar' (bootstrap=0) ---
04-07 04:04:55.141: D/dalvikvm(345): DexOpt: --- END 'ads18470.jar' (success) ---
04-07 04:04:55.141: D/dalvikvm(345): DEX prep '/data/data/com.hello.app/cache/ads18470.jar': unzip in 1ms, rewrite 182ms
04-07 04:04:55.251: D/dalvikvm(345): GC_FOR_MALLOC freed 4110 objects / 299632 bytes in 66ms
04-07 04:04:55.311: I/Ads(345): Use AdRequest.Builder.addTestDevice("B3EEABB8EE11C2BE770B684D95219ECB") to get test ads on this device.
04-07 04:04:55.351: I/Ads(345): Starting ad request.
04-07 04:04:55.731: D/AndroidRuntime(345): Shutting down VM
04-07 04:04:55.731: W/dalvikvm(345): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
04-07 04:04:55.761: E/AndroidRuntime(345): FATAL EXCEPTION: main
04-07 04:04:55.761: E/AndroidRuntime(345): java.lang.RuntimeException: Unable to resume activity {com.hello.app/com.hello.app.MainActivity}: java.lang.IllegalArgumentException: Both context and applicationId must be non-null
04-07 04:04:55.761: E/AndroidRuntime(345):  at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3128)
04-07 04:04:55.761: E/AndroidRuntime(345):  at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3143)
04-07 04:04:55.761: E/AndroidRuntime(345):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2684)
04-07 04:04:55.761: E/AndroidRuntime(345):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-07 04:04:55.761: E/AndroidRuntime(345):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-07 04:04:55.761: E/AndroidRuntime(345):  at android.os.Handler.dispatchMessage(Handler.java:99)
04-07 04:04:55.761: E/AndroidRuntime(345):  at android.os.Looper.loop(Looper.java:123)
04-07 04:04:55.761: E/AndroidRuntime(345):  at android.app.ActivityThread.main(ActivityThread.java:4627)
04-07 04:04:55.761: E/AndroidRuntime(345):  at java.lang.reflect.Method.invokeNative(Native Method)
04-07 04:04:55.761: E/AndroidRuntime(345):  at java.lang.reflect.Method.invoke(Method.java:521)
04-07 04:04:55.761: E/AndroidRuntime(345):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-07 04:04:55.761: E/AndroidRuntime(345):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-07 04:04:55.761: E/AndroidRuntime(345):  at dalvik.system.NativeStart.main(Native Method)
04-07 04:04:55.761: E/AndroidRuntime(345): Caused by: java.lang.IllegalArgumentException: Both context and applicationId must be non-null
04-07 04:04:55.761: E/AndroidRuntime(345):  at com.facebook.AppEventsLogger.activateApp(AppEventsLogger.java:286)
04-07 04:04:55.761: E/AndroidRuntime(345):  at com.hello.app.MainActivity.onResume(MainActivity.java:192)
04-07 04:04:55.761: E/AndroidRuntime(345):  at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1149)
04-07 04:04:55.761: E/AndroidRuntime(345):  at android.app.Activity.performResume(Activity.java:3823)
04-07 04:04:55.761: E/AndroidRuntime(345):  at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3118)
04-07 04:04:55.761: E/AndroidRuntime(345):  ... 12 more
04-07 04:04:56.031: I/dalvikvm(345): Could not find method java.io.IOException.<init>, referenced from method com.google.android.gms.ads.identifier.AdvertisingIdClient.g
04-07 04:04:56.071: W/dalvikvm(345): VFY: unable to resolve direct method 28279: Ljava/io/IOException;.<init> (Ljava/lang/Throwable;)V
04-07 04:04:56.071: D/dalvikvm(345): VFY: replacing opcode 0x70 at 0x0032
04-07 04:04:56.071: D/dalvikvm(345): VFY: dead code 0x0035-0035 in Lcom/google/android/gms/ads/identifier/AdvertisingIdClient;.g (Landroid/content/Context;)Lcom/google/android/gms/common/a;
04-07 04:05:00.681: W/GAV3(345): Thread[GAThread,5,main]: Service unavailable (code=1), will retry.
04-07 04:05:00.681: I/GAV3(345): Thread[GAThread,5,main]: No campaign data found.
04-07 04:05:05.711: W/GAV3(345): Thread[Service Reconnect,5,main]: Service unavailable (code=1), using local store.
04-07 04:05:05.922: D/dalvikvm(345): GC_FOR_MALLOC freed 6190 objects / 372304 bytes in 63ms
04-07 04:05:06.572: D/dalvikvm(345): GC_FOR_MALLOC freed 5121 objects / 284528 bytes in 59ms
04-07 04:05:56.649: W/Ads(345): Timed out waiting for ad response.
04-07 04:09:55.822: I/Process(345): Sending signal. PID: 345 SIG: 9
Was it helpful?

Solution

From your logcat it is clearly seen that you are passing null context.So make following changes in your code.

if(context!=null){
    com.facebook.AppEventsLogger.activateApp(context, "263969900451122");
}

You can get context of application by either

context = this;

or by

context= getActivity().getApplicationContext();

So write these lines above if statement and see if it works properly or not.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top