Java 在应用程序中添加广告?

Java 在应用程序中添加广告?,java,android,xml,Java,Android,Xml,我正在使用以下代码: <com.google.android.gms.ads.AdView android:id="@+id/adView" android:layout_width="wrap_content" android:layout_height="wrap_content" ads:adUnitId="MY_AD_UNIT_ID" ads:adSize="BANNER"/> 您需要添加您的唯一广告单位id。要获得此信息,您需要在设置新的货币化应

我正在使用以下代码:

 <com.google.android.gms.ads.AdView android:id="@+id/adView"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   ads:adUnitId="MY_AD_UNIT_ID"
   ads:adSize="BANNER"/>

您需要添加您的唯一广告单位id。要获得此信息,您需要在设置新的货币化应用程序后,在您的个人资料中创建一个新的横幅广告

编辑: 删除第120行的loadOncreate属性,因为它不能用作XML属性

编辑2: 可能的新解决方案:

添加xmlns:ads=http://schemas.android.com/apk/res-auto 以XML格式发送给您的父母

将Google Play服务添加到您的依赖项:

编译'com.google.android.gms:play services:6.+'

在应用程序的清单中添加元标记: 在应用程序清单中添加adactivity的配置更改和主题:
很好地删除了,错误消失了,但没有显示出来banner@Rodolfo发布关于如何构建广告请求的代码;AdRequest AdRequest=新建AdRequest.Builder.build;adView.loadAdadRequest`@Rodolfo这应该是有效的,当adrequest构建广告时,您的日志是什么?下面消息中的图形布局显示在横幅XML中所需的属性adSize丢失。
Description Resource Path Location Type error: No resource identifier
  found for attribute 'loadAdOnCreate' in package 'com.teste.teste1'
  activity_teste.xml /Teste/res/layout line 120 Android AAPT Problem
    <!--This meta-data tag is required to use Google Play Services.-->
    <meta-data android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
<!--Include the AdActivity configChanges and theme. -->
    <activity android:name="com.google.android.gms.ads.AdActivity"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
        android:theme="@android:style/Theme.Translucent" />