简体   繁体   中英

Binary XML file line #14: Error inflating class com.google.android.gms.ads.AdView

Getting this error working with the AdView class. What is the problem? I've tried Order & Export, closing and reopening Eclipse, and pretty much every suggestion I could find on the net. Nothing worked so I'm here.

Line 14 of the XML file is:

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

Here is said XML file for the activity that contains the AdView (That's not my actual id) :

<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="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:orientation="horizontal"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context=".SearchActivity" >

    <com.google.android.gms.ads.AdView
        android:id = "@+id/adView"
        xmlns:ads="http://schemas.android.com/apk/libs/com.google.ads"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        ads:adSize="MEDIUM_RECTANGLE"
        ads:adUnitId="pub-1234567891234567" >
    </com.google.android.gms.ads.AdView>

    <ListView
        android:id="@+id/list"
        android:layout_width="248dp"
        android:layout_height="392dp"
        android:layout_marginTop="30dp" >
    </ListView>

    <TextView
        android:layout_width="200dp"
        android:layout_height="18dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:text="Search results"/>

</RelativeLayout>

And here is the logcat:

05-18 16:00:00.233: I/Process(6997): Sending signal. PID: 6997 SIG: 9
05-18 16:03:29.038: I/dalvikvm(7141): Could not find method android.content.pm.PackageManager.getActivityLogo, referenced from method android.support.v7.internal.widget.ActionBarView.<init>
05-18 16:03:29.038: W/dalvikvm(7141): VFY: unable to resolve virtual method 511: Landroid/content/pm/PackageManager;.getActivityLogo (Landroid/content/ComponentName;)Landroid/graphics/drawable/Drawable;
05-18 16:03:29.038: D/dalvikvm(7141): VFY: replacing opcode 0x6e at 0x008b
05-18 16:03:29.038: I/dalvikvm(7141): Could not find method android.content.pm.ApplicationInfo.loadLogo, referenced from method android.support.v7.internal.widget.ActionBarView.<init>
05-18 16:03:29.038: W/dalvikvm(7141): VFY: unable to resolve virtual method 504: Landroid/content/pm/ApplicationInfo;.loadLogo (Landroid/content/pm/PackageManager;)Landroid/graphics/drawable/Drawable;
05-18 16:03:29.038: D/dalvikvm(7141): VFY: replacing opcode 0x6e at 0x0099
05-18 16:03:29.042: D/dalvikvm(7141): VFY: dead code 0x008e-0092 in Landroid/support/v7/internal/widget/ActionBarView;.<init> (Landroid/content/Context;Landroid/util/AttributeSet;)V
05-18 16:03:29.042: D/dalvikvm(7141): VFY: dead code 0x009c-00a0 in Landroid/support/v7/internal/widget/ActionBarView;.<init> (Landroid/content/Context;Landroid/util/AttributeSet;)V
05-18 16:03:29.116: D/skia(7141): purging 6K from font cache [1 entries]
05-18 16:03:29.116: D/SKIA_FONT(7141): stored typeface in slot 0
05-18 16:03:29.116: D/SKIA_FONT(7141): SKIA_FONT fontfile: /data/data/com.android.settings/app_fonts/default/DroidSans.ttf
05-18 16:03:29.116: D/SKIA_FONT(7141): SKIA_FONT fontfile: /data/data/com.android.settings/app_fonts/default/DroidSans.ttf
05-18 16:03:29.116: D/SKIA_FONT(7141): load_system_fonts(), name = Droid Sans, style = 0, uniqueID = 13
05-18 16:03:29.120: D/SKIA_FONT(7141): SKIA_FONT fontfile: /data/data/com.android.settings/app_fonts/default/DroidSans-Bold.ttf
05-18 16:03:29.120: D/SKIA_FONT(7141): SKIA_FONT fontfile: /data/data/com.android.settings/app_fonts/default/DroidSans-Bold.ttf
05-18 16:03:29.120: D/SKIA_FONT(7141): load_system_fonts(), name = Droid Sans, style = 1, uniqueID = 14
05-18 16:03:29.128: D/SKIA_FONT(7141): load_system_fonts(), name = Droid Serif, style = 0, uniqueID = 15
05-18 16:03:29.135: D/SKIA_FONT(7141): load_system_fonts(), name = Droid Serif, style = 1, uniqueID = 16
05-18 16:03:29.143: D/SKIA_FONT(7141): load_system_fonts(), name = Droid Serif, style = 2, uniqueID = 17
05-18 16:03:29.167: D/SKIA_FONT(7141): load_system_fonts(), name = Droid Serif, style = 3, uniqueID = 18
05-18 16:03:29.171: D/SKIA_FONT(7141): load_system_fonts(), name = Droid Sans Mono, style = 0, uniqueID = 19
05-18 16:03:29.171: D/SKIA_FONT(7141): load_system_fonts(), name = Droid Sans Arabic, style = 0, uniqueID = 20
05-18 16:03:29.171: D/SKIA_FONT(7141): load_system_fonts(), name = Droid Sans Hebrew, style = 0, uniqueID = 21
05-18 16:03:29.175: D/SKIA_FONT(7141): load_system_fonts(), name = Droid Sans Thai, style = 0, uniqueID = 22
05-18 16:03:29.178: D/SKIA_FONT(7141): load_system_fonts(), name = Droid Sans, style = 0, uniqueID = 23
05-18 16:03:29.198: D/SKIA_FONT(7141): load_system_fonts(), name = Droid Sans Fallback, style = 0, uniqueID = 24
05-18 16:03:29.198: D/SKIA_FONT(7141): load_system_fonts(), oldSansUID = 1, newSansUID = 13
05-18 16:03:29.198: D/SKIA_FONT(7141): load_system_fonts(), oldSansBoldUID = 2, newSansBoldUID = 14
05-18 16:03:32.210: D/SearchDialog(7141): launching Intent { act=android.intent.action.SEARCH flg=0x10000000 cmp=com.example.activity2/.SearchActivity (has extras) }
05-18 16:03:32.214: I/SearchDialog(7141): Starting (as ourselves) #Intent;action=android.intent.action.SEARCH;launchFlags=0x10000000;component=com.example.activity2/.SearchActivity;S.query=J;S.user_query=J;end
05-18 16:03:32.288: I/System.out(7141): file is /mnt/sdcard
05-18 16:03:32.292: W/dalvikvm(7141): VFY: unable to resolve static field 4641 (AdsAttrs) in Lcom/google/android/gms/R$styleable;
05-18 16:03:32.292: D/dalvikvm(7141): VFY: replacing opcode 0x62 at 0x0009
05-18 16:03:32.292: D/dalvikvm(7141): VFY: dead code 0x000b-0068 in Lcom/google/android/gms/internal/ao;.<init> (Landroid/content/Context;Landroid/util/AttributeSet;)V
05-18 16:03:32.303: D/AndroidRuntime(7141): Shutting down VM
05-18 16:03:32.303: W/dalvikvm(7141): threadid=1: thread exiting with uncaught exception (group=0x4001d7d0)
05-18 16:03:32.339: D/dalvikvm(7141): GC_FOR_MALLOC freed 3272 objects / 222072 bytes in 30ms
05-18 16:03:32.358: E/AndroidRuntime(7141): FATAL EXCEPTION: main
05-18 16:03:32.358: E/AndroidRuntime(7141): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.activity2/com.example.activity2.SearchActivity}: android.view.InflateException: Binary XML file line #14: Error inflating class com.google.android.gms.ads.AdView
05-18 16:03:32.358: E/AndroidRuntime(7141):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
05-18 16:03:32.358: E/AndroidRuntime(7141):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-18 16:03:32.358: E/AndroidRuntime(7141):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-18 16:03:32.358: E/AndroidRuntime(7141):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-18 16:03:32.358: E/AndroidRuntime(7141):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-18 16:03:32.358: E/AndroidRuntime(7141):     at android.os.Looper.loop(Looper.java:123)
05-18 16:03:32.358: E/AndroidRuntime(7141):     at android.app.ActivityThread.main(ActivityThread.java:4627)
05-18 16:03:32.358: E/AndroidRuntime(7141):     at java.lang.reflect.Method.invokeNative(Native Method)
05-18 16:03:32.358: E/AndroidRuntime(7141):     at java.lang.reflect.Method.invoke(Method.java:521)
05-18 16:03:32.358: E/AndroidRuntime(7141):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
05-18 16:03:32.358: E/AndroidRuntime(7141):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
05-18 16:03:32.358: E/AndroidRuntime(7141):     at dalvik.system.NativeStart.main(Native Method)
05-18 16:03:32.358: E/AndroidRuntime(7141): Caused by: android.view.InflateException: Binary XML file line #14: Error inflating class com.google.android.gms.ads.AdView
05-18 16:03:32.358: E/AndroidRuntime(7141):     at android.view.LayoutInflater.createView(LayoutInflater.java:513)
05-18 16:03:32.358: E/AndroidRuntime(7141):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
05-18 16:03:32.358: E/AndroidRuntime(7141):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
05-18 16:03:32.358: E/AndroidRuntime(7141):     at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
05-18 16:03:32.358: E/AndroidRuntime(7141):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
05-18 16:03:32.358: E/AndroidRuntime(7141):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
05-18 16:03:32.358: E/AndroidRuntime(7141):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:200)
05-18 16:03:32.358: E/AndroidRuntime(7141):     at android.app.Activity.setContentView(Activity.java:1647)
05-18 16:03:32.358: E/AndroidRuntime(7141):     at com.example.activity2.SearchActivity.onCreate(SearchActivity.java:76)
05-18 16:03:32.358: E/AndroidRuntime(7141):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
05-18 16:03:32.358: E/AndroidRuntime(7141):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-18 16:03:32.358: E/AndroidRuntime(7141):     ... 11 more
05-18 16:03:32.358: E/AndroidRuntime(7141): Caused by: java.lang.reflect.InvocationTargetException
05-18 16:03:32.358: E/AndroidRuntime(7141):     at com.google.android.gms.ads.AdView.<init>(Unknown Source)
05-18 16:03:32.358: E/AndroidRuntime(7141):     at java.lang.reflect.Constructor.constructNative(Native Method)
05-18 16:03:32.358: E/AndroidRuntime(7141):     at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
05-18 16:03:32.358: E/AndroidRuntime(7141):     at android.view.LayoutInflater.createView(LayoutInflater.java:500)
05-18 16:03:32.358: E/AndroidRuntime(7141):     ... 21 more
05-18 16:03:32.358: E/AndroidRuntime(7141): Caused by: java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
05-18 16:03:32.358: E/AndroidRuntime(7141):     at com.google.android.gms.internal.ao.<init>(Unknown Source)
05-18 16:03:32.358: E/AndroidRuntime(7141):     at com.google.android.gms.internal.au.<init>(Unknown Source)
05-18 16:03:32.358: E/AndroidRuntime(7141):     at com.google.android.gms.internal.au.<init>(Unknown Source)
05-18 16:03:32.358: E/AndroidRuntime(7141):     ... 25 more
05-18 16:08:37.901: I/Process(7141): Sending signal. PID: 7141 SIG: 9

Any suggestions? Been trying to get this very simple AdView to work all day. Thanks.

Replace this line:

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

with

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

The namespace is under the lib name not libs.

and make sure you have the google play services in your build.gradle

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.google.android.gms:play-services:7.0.0'
}

Don't put google-play-services.jar in the /libs/ folder. Instead, reference the google play services library in your project.

Import the library into your workspace. You'll find it in sdk/extras/google/.. if you downloaded via the sdk manager. Then reference by right clicking your project => selecting properties => Android => Add

First attached Google play services in your app properly, then add xml-name-space in layout xml file.

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

then use this

<com.google.android.gms.ads.AdView
    android:id="@+id/adView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_gravity="center"
    ads:adSize="BANNER"
    ads:adUnitId="Your AddUnitID" />

add this in manifiest.xml

    <activity
                android:name="com.google.android.gms.ads.AdActivity"
                android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
                android:screenOrientation="portrait" />

            <meta-data
                android:name="com.google.android.gms.version"
                android:value="@integer/google_play_services_version" />

and add permission

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM