Domanda

I cannot add adverts to my android app, I have spent the last 6 hours trying to get it to work and researching fixes, but nothing seems to work! So frustrating.

here is the code:

setContentView(R.layout.splash);
    init();
    LinearLayout layout = (LinearLayout) findViewById(R.id.linearSplash);

    adView = new AdView(this);
    adView.setAdSize(AdSize.BANNER);
    adView.setAdUnitId("a14ff402be4457c");

    layout.addView(adView);
    AdRequest adRequest = new AdRequest.Builder()
    .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
    .build();

    adView.loadAd(adRequest);

But I get the error:

Unable to start activity - android.view.InflateException: Binary XML file line #17: Error inflating class com.google.gms.ads.AdView

Is there a fix? I am using the google play services jar file, not the normal admob 6.4.1 one.

È stato utile?

Soluzione

You have the wrong AdView in your layout file.

You have to use com.google.android.gms.ads.AdView in your layout as google play services has that package and not the one that you use currently(probably com.google.gms.ads.AdView)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top