广告尺寸和广告单元ID必须loadAd之前设置被称为 [英] Ad Size and Ad unit id must be set before loadAd is called
本文介绍了广告尺寸和广告单元ID必须loadAd之前设置被称为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个在我的主XML文件:
I have this in my main xml file:
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="******************"
ads:adSize="BANNER"
android:id="@+id/adView"/>
我已经设置了广告尺寸和单位的ID,但是当这种运行(从MainActivity.java),
I have already set the ad size and unit id, but when this is run (from MainActivity.java),
AdView adView = (AdView)this.findViewById(com.example.lovetestactual.R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
这引发了异常的是什么的称号。
It threw an exception of what is in the title.
推荐答案
我发现,在github上示例解决方案,那就是:
I found solution in the github example, that is:
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
删除的xmlns:广告***标记,并添加
delete the xmlns:ads*** tag and add
xmlns:ads="http://schemas.android.com/apk/res-auto"
标签到您的LinearLayout标签如下:
tag to your LinearLayout tag as follow:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/hello"/>
<com.google.android.gms.ads.AdView android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="INSERT_YOUR_AD_UNIT_ID_HERE"/>
</LinearLayout>
就是这样:)
That's it :)
<一个href="https://github.com/googleads/googleads-mobile-android-examples/blob/master/admob/banner-xml/res/layout/main.xml">github链接这个XML
这篇关于广告尺寸和广告单元ID必须loadAd之前设置被称为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文