2014-04-06 46 views
2

我正在運行Facebook的移動安裝廣告,這就是爲什麼我添加Facebook SDK到我的應用程序來跟蹤安裝,並按照說明添加代碼。但現在我正在接近力量,我也檢查了所有新的和舊的Android版本。當我評論代碼都工作正常。如何擺脫強制關閉添加Facebook Sdk跟蹤移動應用安裝廣告?

這裏是代碼,我添加了什麼: -

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

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

... 

所有工作正常,但當我按照指示在加的onResume添加此代碼,程序是強制關閉:

com.facebook。 AppEventsLogger.activateApp(context,「263969900451122」);


按要求的記錄貓: -

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 
+0

你可以發佈logcat嗎?或你得到的例外? – Rahil2952

+0

@ Rahil2952根據你問我發佈logcat –

回答

2

從你的logcat可以清楚地看出,你是通過null context.So使你的代碼以下更改。

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

您可以通過

context = this; 

得到應用的上下文或通過

context= getActivity().getApplicationContext(); 

所以寫這幾行上面的if語句,看看它是否工作正常與否。

+0

我應該寫什麼來代替上下文,以便它不會爲空 –

+0

@DeepakSIngh看看這是否適合你.. – Rahil2952

+0

非常感謝.. :-) –

相關問題