문제

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.

도움이 되었습니까?

해결책

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)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top