您好,我正在尝试将广告添加到我的应用程序中,但我一直收到错误消息
The ad size and ad unit ID must be set before load is called.
这是我到目前为止所做的尝试
这是我的布局(我有实际的 adUnitId 号,我已经把它放在我的应用程序的 xml 中,只是没有把它放在这里,因为我认为在线发布它不是一个好主意)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/levelView"
>
<RelativeLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="70dp"
>
<TextView
android:id="@+id/tv1"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:textSize="15dp"
android:textColor="@color/white"
android:text="hello"
android:gravity="center"
android:singleLine="true"/>
<TextView
android:id="@+id/headertitle"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@+id/headertitle"
android:textSize="40dp"
android:textColor="@color/white"
android:layout_marginTop="15dp"
android:text="2014"
android:gravity="center"
android:singleLine="true"/>
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="18dp"
android:layout_toRightOf="@+id/headertitle"
android:src="@drawable/level_logo" />
</RelativeLayout>
<GridView
android:id="@+id/gridView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/header"
android:numColumns="4"
android:listSelector="@null"
android:layout_centerHorizontal="true" >
</GridView>
<com.google.android.gms.ads.AdView android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/gridView1"
ads:adUnitId="MY ID NUMBER"
ads:adSize="BANNER"/>
</RelativeLayout>
然后在我的 onCreate() 中运行以下函数
public void loadAds(){
// Look up the AdView as a resource and load a request.
AdView adView = (AdView)this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
}
有谁知道这个错误是什么意思,我该如何解决?
最佳答案
更改 xmlns:ads
模式
来自
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
到
xmlns:ads="http://schemas.android.com/apk/res-auto"
关于Android AdMob 错误调用加载前必须设置广告尺寸和广告单元 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23397574/