2013-12-19 11 views
1

Я следую инструкциям в официальной ссылке, и я не могу найти, где проблема. Я скачал эти библиотеки из: https://developers.google.com/mobile-ads-sdk/download#downloadandroid Это мой код: В MainActivity я добавить:Admob: Не удалось инициализировать AdView: Обязательный атрибут XML «adSize» отсутствует

adView = (AdView) findViewById(R.id.ad); 
AdRequest adRequest = new AdRequest(); 
adView.loadAd(adRequest); 

В манифесте:

<uses-permission android:name="android.permission.INTERNET" /> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
<activity android:name="com.google.ads.AdActivity"      android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" /> 

И XML: редактирование

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/lytMain" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:ads="http://schemas.android.com/apk/libs/com.google.ads" 
    android:layout_width="fill_parent" android:layout_height="fill_parent"> 

    <com.google.ads.AdView 
    android:id="@+id/ad" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    ads:adSize="BANNER" 
    ads:adUnitId="ca-app-pub-xxxxxxxx/xxxxxx" 
    ads:testDevices="TEST_EMULATOR" 
    ads:loadAdOnCreate="true" > 
</com.google.ads.AdView> 
    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="2" 
     android:gravity="center" 
    > 
    <TextView 
     android:id="@+id/cargando" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Cargando resultados..." 
     android:textColor="@android:color/black" 
     android:textSize="20sp" /> 


    <ProgressBar 
     android:id="@+id/progress" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     style="@android:style/Widget.ProgressBar.Small.Inverse" 
     android:layout_marginRight="5dp" /> 

    <Button 
    android:id="@+id/button" 
    android:visibility="invisible" 
    android:layout_marginTop="10dp" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:text="Ver resultados" /> 


</LinearLayout> 
</LinearLayout> 
+0

Это сбой происходит во время работы приложения. Если это так, вы получите полную стек. Также вы можете проверить adUnitId правильно или нет? – Triode

+0

В журнале у меня есть threadid = 1: Не удалось инициализировать AdView: отсутствует атрибут XML adSize; thread exiting with uncaught exception (group = 0x41af1438) – user3118803

ответ

0

Try это и использовать.

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:ads="http://schemas.android.com/apk/res/com.jms.AdmobExample" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <com.google.ads.AdView 
     xmlns:ads="http://schemas.android.com/apk/res/com.jms.AdmobExample" 
     android:id="@+id/add_view" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"    
     ns:adSize="BANNER" 
     ns:adUnitId="a14f1d807e488dd" > 
    </com.google.ads.AdView> 

</Linearlayout> 
+0

Что такое http://schemas.android.com/apk/res/com.jms.AdmobExample?? – user3118803

+0

и adUnitId, не похоже на ca-app-pub-xxxxxxxx/xxxxxx? – user3118803

+0

рекламный блок будет выглядеть так: @ user3118803 – Yogamurthy

1

В новейшей SDK:

XML:

<com.google.android.gms.ads.AdView 
    xmlns:ads="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/adView" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    ads:adSize="BANNER" 
    ads:adUnitId="xxxxxxxxxxxxxxxxxxxx" /> 

Код:

adView = (AdView) findViewById(R.id.adView);  
AdRequest adRequest = new AdRequest.Builder().build(); 
adView.loadAd(adRequest); 
Смежные вопросы