admob广告没有出现,也没有错误

时间:2015-10-31 15:39:00

标签: android admob

我使用admob广告创建了一个简单的应用,但广告没有显示且没有错误,API级别为21。

这是我的代码:

xml文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<com.google.android.gms.ads.AdView
    android:id="@+id/adView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_marginBottom="76dp"
    ads:adSize="SMART_BANNER"
    ads:adUnitId="ca-app-pub-2615894909216466/7973602032">
     </com.google.android.gms.ads.AdView>

</RelativeLayout>

java文件:

 AdView adView = (AdView) findViewById(R.id.adView);
 AdRequest request = new AdRequest.Builder().build();
 adView.loadAd(request);

logcat消息:

10-31 16:30:11.267: W/ScreenOrientationListener(1199): Removing an       inexistent observer!
10-31 16:30:11.383: W/Ads(1199): There was a problem getting an ad response. ErrorCode: 0
10-31 16:30:11.506: W/art(1199): Attempt to remove local handle scope entry from IRT, ignoring
10-31 16:30:11.547: W/AwContents(1199): onDetachedFromWindow called when already detached. Ignoring
10-31 16:30:11.647: W/art(1199): Attempt to remove local handle scope entry from IRT, ignoring
10-31 16:30:11.730: W/Ads(1199): Failed to load ad: 0

1 个答案:

答案 0 :(得分:0)

确保:

  1. 您的清单文件中拥有Internet权限 名称=&#34; banner_ad_unit_id&#34;&GT; yourAppID
  2. 您的Java类中有这一行:MobileAds.initialize(mainActivity.getApplicationContext(),&#34; YourAppID&#34;);