其他分享
首页 > 其他分享> > android-二进制XML文件第6行:膨胀类com.google.ads.AdView时出错

android-二进制XML文件第6行:膨胀类com.google.ads.AdView时出错

作者:互联网

我的logcat在向我的项目中添加admob时显示此类错误.我尝试手动添加sdk jar文件,但仍然无法正常工作.我的libs文件夹由jars-google-play-services和
  android-support-v4.i曾提及其他帖子,但发生了相同的错误,但对我没有任何帮助.

日志猫

07-02 00:26:42.082: E/AndroidRuntime(26811): FATAL EXCEPTION: main
07-02 00:26:42.082: E/AndroidRuntime(26811): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.xmlpullparserproject/com.example.xmlpullparserproject.MainActivity}: android.view.InflateException: Binary XML file line #6: Error inflating class com.google.ads.AdView
07-02 00:26:42.082: E/AndroidRuntime(26811):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
07-02 00:26:42.082: E/AndroidRuntime(26811):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2211)
07-02 00:26:42.082: E/AndroidRuntime(26811):    at android.app.ActivityThread.access$600(ActivityThread.java:149)
07-02 00:26:42.082: E/AndroidRuntime(26811):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1300)
07-02 00:26:42.082: E/AndroidRuntime(26811):    at android.os.Handler.dispatchMessage(Handler.java:99)
07-02 00:26:42.082: E/AndroidRuntime(26811):    at android.os.Looper.loop(Looper.java:153)
07-02 00:26:42.082: E/AndroidRuntime(26811):    at android.app.ActivityThread.main(ActivityThread.java:5086)
07-02 00:26:42.082: E/AndroidRuntime(26811):    at java.lang.reflect.Method.invokeNative(Native Method)
07-02 00:26:42.082: E/AndroidRuntime(26811):    at java.lang.reflect.Method.invoke(Method.java:511)
07-02 00:26:42.082: E/AndroidRuntime(26811):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
07-02 00:26:42.082: E/AndroidRuntime(26811):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
07-02 00:26:42.082: E/AndroidRuntime(26811):    at dalvik.system.NativeStart.main(Native Method)
07-02 00:26:42.082: E/AndroidRuntime(26811): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class com.google.ads.AdView
07-02 00:26:42.082: E/AndroidRuntime(26811):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:698)
07-02 00:26:42.082: E/AndroidRuntime(26811):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
07-02 00:26:42.082: E/AndroidRuntime(26811):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
07-02 00:26:42.082: E/AndroidRuntime(26811):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
07-02 00:26:42.082: E/AndroidRuntime(26811):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
07-02 00:26:42.082: E/AndroidRuntime(26811):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:258)
07-02 00:26:42.082: E/AndroidRuntime(26811):    at android.app.Activity.setContentView(Activity.java:1867)
07-02 00:26:42.082: E/AndroidRuntime(26811):    at com.example.xmlpullparserproject.MainActivity.onCreate(MainActivity.java:31)
07-02 00:26:42.082: E/AndroidRuntime(26811):    at android.app.Activity.performCreate(Activity.java:5020)
07-02 00:26:42.082: E/AndroidRuntime(26811):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
07-02 00:26:42.082: E/AndroidRuntime(26811):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
07-02 00:26:42.082: E/AndroidRuntime(26811):    ... 11 more
07-02 00:26:42.082: E/AndroidRuntime(26811): Caused by: java.lang.ClassNotFoundException: com.google.ads.AdView
07-02 00:26:42.082: E/AndroidRuntime(26811):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
07-02 00:26:42.082: E/AndroidRuntime(26811):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
07-02 00:26:42.082: E/AndroidRuntime(26811):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
07-02 00:26:42.082: E/AndroidRuntime(26811):    at android.view.LayoutInflater.createView(LayoutInflater.java:552)
07-02 00:26:42.082: E/AndroidRuntime(26811):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
07-02 00:26:42.082: E/AndroidRuntime(26811):    ... 21 more

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:layout_width="match_parent"
    android:layout_height="match_parent" >
<com.google.ads.AdView android:id="@+id/adView"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         ads:adUnitId="xyz"
                         ads:adSize="BANNER"

                         />
    <ListView
        android:id="@+id/lv_countries"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"        
        tools:context=".MainActivity" />

</RelativeLayout>

主活动

setContentView(R.layout.activity_main);

        AdView adView = (AdView)this.findViewById(R.id.adView);

        AdRequest adRequest = new AdRequest.Builder()
        .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)       // 
        .addTestDevice("3a2d1115ab64e3") // 
         .build() ;
        adView.loadAd(adRequest);

解决方法:

广告xml名称空间有误:

在GoogleAdMobAdsSdk-6.4.1.jar或更早版本中,您可以使用:

<com.google.ads.AdView 

与名称空间:

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

在通过播放服务库的Google admob中,您可以使用:

<com.google.android.gms.ads.AdView

与名称空间:

 xmlns:ads="http://schemas.android.com/apk/res-auto

标签:admob,android
来源: https://codeday.me/bug/20191121/2052664.html