2013-08-27 30 views
16

Tôi đang cố thêm admob vào ứng dụng Android của mình trong studio android. Tôi gần như có nhưng đang nhận được lỗi của:Không gian tên 'quảng cáo' không bị ràng buộc

Namespace 'ads' not bound 

Đây cũng là xml của tôi với quảng cáo:

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" > 

     <com.google.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" 
           ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID" 
           ads:loadAdOnCreate="true"/> 


    <TextView 
     android:id="@+id/beerTitle" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:ems="10" 
     android:textSize="20sp" 
     android:textStyle = "bold" 
     android:padding="5dip" 
     > 
    </TextView> 

    <ImageView android:id="@+id/image" 
     android:layout_height="fill_parent" 
     android:layout_width="fill_parent" 
     android:layout_margin="10dip"/> 



    <TableLayout 

    android:id="@+id/tableLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_gravity="center_horizontal" 
    android:shrinkColumns="*" 
    android:stretchColumns="*"> 

    <TableRow 
     android:id="@+id/tableStatTitles" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 

     android:padding="5dip" > 

     <TextView 
      android:id="@+id/abvTitle" 
      android:text="ABV" 
      android:gravity="center" 
      android:textStyle = "bold" 
      android:textSize="20sp" 
      android:layout_weight="1" 

      ></TextView> 

     <TextView 
      android:id="@+id/IBUTitle" 
      android:text="IBU" 
      android:gravity="center" 
      android:textStyle = "bold" 
      android:textSize="20sp" 
      android:layout_weight="1" 

      ></TextView> 

     <TextView 
      android:id="@+id/glassTitle" 
      android:text="Glass" 
      android:gravity="center" 
      android:textStyle = "bold" 
      android:textSize="20sp" 
      android:layout_weight="1" 
      android:layout_width="wrap_content" 
      ></TextView> 




     </TableRow> 

    <TableRow 
     android:id="@+id/tableStat" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 

     android:padding="5dip" > 

     <TextView 
      android:id="@+id/abv" 
      android:text="" 
      android:gravity="center" 
      android:textSize="15sp" 
      android:layout_width="wrap_content" 
      ></TextView> 

     <TextView 
      android:id="@+id/IBU" 
      android:text="" 
      android:gravity="center" 
      android:textSize="15sp" 
      android:layout_width="wrap_content" 
      ></TextView> 

     <TextView 
      android:id="@+id/glass" 
      android:text="" 
      android:gravity="center" 
      android:textSize="15sp" 
      android:layout_width="wrap_content" 
      ></TextView> 


     </TableRow> 

    </TableLayout> 

    <View 
    android:layout_width="1dp" 
    android:layout_height="30dp"> 
</View> 

    <LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" > 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Average Rating: " 
     android:textStyle = "bold" 
     android:textSize="20sp" 
     /> 

    <TextView 
     android:id="@+id/beerRating" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="" 
     android:textSize="20sp" 
     /> 

    </LinearLayout> 

    <View 
    android:layout_width="1dp" 
    android:layout_height="30dp"> 
</View> 

    <Button 
     android:id="@+id/buttonBrewery" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:padding="5dip" 
     android:text="" 
     android:onClick="viewBrewery" 
     /> 



    <Button 
     android:id="@+id/buttonStyle" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:padding="5dip" 
     android:text="" 
     android:onClick="viewStyle" 

     /> 

    <View 
    android:layout_width="1dp" 
    android:layout_height="30dp"> 
</View> 

    <TextView 
     android:id="@+id/yourPortfolio" 
     android:textStyle = "bold" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:ems="10" 
     android:textSize="20sp" 
     android:text="Your Portfolio:" 
     android:padding="5dip" 
     ></TextView> 

    <LinearLayout 
    android:id="@+id/addBeerLayout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" > 

     </LinearLayout> 

    <TextView 
     android:id="@+id/beerDescriptionTitle" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:ems="10" 
     android:padding="5dip" 
     android:text="Description:" 
     android:textSize="20sp" 
     android:textStyle="bold" > 
</TextView> 
    <TextView 
     android:id="@+id/beerDescription" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:ems="10" 
     android:textSize="15sp" 
     android:padding="5dip" 

     ></TextView> 


    <Button 
     android:id="@+id/buttonTasteTag" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:padding="5dip" 
     android:text="Taste Profile" 
     android:onClick="viewTasteTags" 

     /> 



</LinearLayout> 
</ScrollView> 

Trả lời

32

Bạn phải thêm namespace này:

xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 

Chỉ cần dán nó bên dưới không gian tên android:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

Ngoài ra, hãy nhớ rằng kể từ khi cập nhật 17 của SDK Tools, bạn có thể sử dụng http://schemas.android.com/apk/res-auto thay vì bất kỳ không gian tên đủ điều kiện + tên gói (more info).

Vì vậy, đây cũng nên làm việc:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:auto="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 
+1

res-auto, nhưng không phải là người đầu tiên –

+0

đồng ý với @NelsonWu! Kết quả đầu tiên trong một Ngoại lệ thời gian chạy khác [Kích thước quảng cáo và ID đơn vị quảng cáo phải được đặt trước khi loadAd được gọi là] (http://stackoverflow.com/questions/23337802/ad-size-and-ad-unit-id-must -be-set-before-loadad-được gọi là) –

0

một không gian tên nên được thêm vào phần tử gốc xml của bạn: D

xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 

thêm dòng đó vào thẻ đầu hoặc phần tử bên trong tập tin xml của bạn và bạn đã sẵn sàng để đi.

0

Thêm dòng mã này để phần tử gốc của bạn

xmlns: Quảng cáo = "http://schemas.android.com/apk/lib/com.google.ads" công trình

Các vấn đề liên quan