简体   繁体   中英

interstitial won't let app launch

I've got a problem: I'm trying to add interstitial ads in my app, I thought it would be easy because I already have conventional one and it works perfectly, but something gone wrong..

Here's my code ( in_app_billing_system ):

 import com.google.android.gms.ads.AdListener;
 import com.google.android.gms.ads.AdRequest;
 import com.google.android.gms.ads.AdSize;
 import com.google.android.gms.ads.AdView;
 import com.google.android.gms.ads.InterstitialAd;
 ...
 ...
 ...
 mInterstitialAd = new InterstitialAd(this);
 mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
 AdRequest adRequestI = new AdRequest.Builder().addTestDevice("bla bla bla").build();
 mInterstitialAd.loadAd(adRequestI);

And here's my error:

08-07 10:03:00.495 13565-13565/? E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: ****, PID: 13565 java.lang.RuntimeException: Unable to start activity ComponentInfo{*****.ActMain}: java.lang.NullPointerException at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2237) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2286) at android.app.ActivityThread.access$800(ActivityThread.java:144) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:212) at android.app.ActivityThread.main(ActivityThread.java:5135) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:877) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.NullPointerException at android.content. ContextWrapper.getPackageManager(ContextWrapper.java:94) at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source) at com.google.android.gms.ads.internal.util.client.zza.zzP(Unknown Source) at com.google.android.gms.ads.internal.client.zze.zzb(Unknown Source) at com.google.android.gms.ads.internal.client.zzz.zzL(Unknown Source) at com.google.android.gms.ads.internal.client.zzz.zza(Unknown Source) at com.google.android.gms.ads.InterstitialAd.loadAd(Unknown Source) at ****.InAppBillingSystem.(InAppBillingSystem.java:46) at ****.ActMain.onCreate(ActMain.java:59) at android.app.Activity.performCreate(Activity.java:5231) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2201) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2286) at android.app.ActivityThread.access$800(ActivityThread.java:144) at android.app.ActivityThread$H. handleMessage(ActivityThread.java:1246) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:212) at android.app.ActivityThread.main(ActivityThread.java:5135) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:877) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693) at dalvik.system.NativeStart.main(Native Method)

I tried to use original Google code from here but the result is the same.

The code at Line 59 in Main Activity:

  //INSTALL APP
    if (IS_FIRST_START) tablesInit();

    if (loadFromPref("registered", "").equals("yes")) {
        is_purchased = true;
    } else {
        is_purchased = false;
 **59:    in_app_billing_system = new InAppBillingSystem(this);**
    }

I never used this type of ads, maybe I have missed something?

PS Don't be confused with name "in_app_billing_system" it's from old times and now I have no in-app but ads there.

It was due to the line:

mInterstitialAd = new InterstitialAd(this);

Instead what I should have used:

mInterstitialAd = new InterstitialAd(myActivity);

The problem has been solved.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM