【问题标题】:Adview Error Parsing XML Unbound Prefix AndroidAdview 解析 XML 未绑定前缀 Android 时出错
【发布时间】:2023-03-25 14:18:02
【问题描述】:

我在让 AdMob 正常工作时遇到了麻烦。我犯了一个又一个错误,并且不止一次地报废了整个事情。现在我从 XML 中得到一个错误,说它解析不正确。这是它的代码。我已经查看了其他答案,但我似乎无法弄清楚出了什么问题。如果有人可以查看我的布局文件并让我知道我做错了什么,我会非常感谢。我直接使用适用于我自己的应用程序的 AdMob 网站的代码。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:id="@+id/AdLinearLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:orientation="vertical" >

<!-- Ad Placeholder -->

<com.google.ads.AdView
    android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    ads:adSize="BANNER"
    ads:adUnitId="a15138b1a7adad2"
    ads:loadAdOnCreate="true"
    ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID" />

<ScrollView
    android:id="@+id/BaseScrollView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

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

        <LinearLayout
            android:id="@+id/LinearLayoutH1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/textView1"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="left"
                android:text="@string/Sad" />

            <TextView
                android:id="@+id/textView2"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="right"
                android:text="@string/Happy" />
        </LinearLayout>

        <SeekBar
            android:id="@+id/happinessBarID"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:max="@integer/SliderMax"
            android:progress="@integer/SliderDefault" />

        <LinearLayout
            android:id="@+id/LinearLayoutH2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/textView3"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="left"
                android:text="@string/Tired" />

            <TextView
                android:id="@+id/textView4"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="right"
                android:text="@string/Awake" />
        </LinearLayout>

        <SeekBar
            android:id="@+id/energyBarID"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:max="@integer/SliderMax"
            android:progress="@integer/SliderDefault" />

        <LinearLayout
            android:id="@+id/LinearLayoutH3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/textView5"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="left"
                android:text="@string/Calm" />

            <TextView
                android:id="@+id/textView6"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="right"
                android:text="@string/Anxious" />
        </LinearLayout>

        <SeekBar
            android:id="@+id/anxietyBarID"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:max="@integer/SliderMax"
            android:progress="@integer/SliderDefault" />

        <LinearLayout
            android:id="@+id/LinearLayoutH4"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/textView7"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="left"
                android:text="@string/No_Pain" />

            <TextView
                android:id="@+id/textView8"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="right"
                android:text="@string/Max_Pain" />
        </LinearLayout>

        <SeekBar
            android:id="@+id/painBarID"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:max="@integer/SliderMax"
            android:progress="@integer/SliderDefault" />

        <DatePicker
            android:id="@+id/datePicker1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <TimePicker
            android:id="@+id/timePicker1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <EditText
            android:id="@+id/noteTextFieldID"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:hint="@string/Note_Hint"
            android:inputType="textMultiLine"
            android:maxLength="@integer/NoteLimit" />

        <Button
            android:id="@+id/enterButtonID"
            android:layout_width="132dp"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:onClick="dialogPop"
            android:text="@string/EnterButtonText" />
    </LinearLayout>
</ScrollView>

【问题讨论】:

    标签: android layout xml-parsing admob


    【解决方案1】:

    变化:

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

    到

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

    AdMob 要求您使用其包中定义的属性。为了不必每次都输入该 URL,我们使用xmlns 声明一个 XML 命名空间,就像我们为 android 所做的那样。您在声明前加上 android 而不是 xmlns,这导致了您的错误。

    【讨论】:

    • 就是这样吗?为什么一定要那样?我问为什么,因为它会帮助我了解未来。
    • Raghav,说明这背后的原因,这样他/她就会知道,我相信他/她不会再犯这样的错误了。
    • 噢噢噢!!!现在犯罪我觉得很愚蠢,但现在它是有道理的。非常感谢您的解决方案(更重要的是)背后的推理。是的,我不会很快再这样做。 =)
    【解决方案2】:

    将此行添加到您的布局中

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多