Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AdMob - Error inflating Class com.google.gms.AdView

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.

like image 938
user3241507 Avatar asked Jul 04 '26 05:07

user3241507


1 Answers

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)

like image 179
Apoorv Avatar answered Jul 06 '26 20:07

Apoorv



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!