Error inflating class com google ads adview

Hello I am new to android dev and admob. I am trying to make a simple test app with a button, a couple pages and admob at the bottom. Everything works fine until I try implementing admob. Here is m...

Hello I am new to android dev and admob. I am trying to make a simple test app with a button, a couple pages and admob at the bottom. Everything works fine until I try implementing admob. Here is my code:

HelloAndroid.java:

package com.manny.HelloAndroid;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

public class HelloAndroid extends Activity {
    /** Called when the activity is first created. */
    private static final int ACTIVITY_CREATE = 0;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        setContentView(R.layout.main);
        ImageView image = (ImageView) findViewById(R.id.test_image);
        //image.setScaleType(ImageView.ScaleType.FIT_XY);

    }
    public void onClick(View v){
        Intent i = new Intent(this, HelloPage2.class);
        startActivityForResult(i, ACTIVITY_CREATE);
    }
}

main.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ImageView 
        android:id="@+id/test_image"
        android:src="@drawable/bak_vert_480x800"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:scaleType="fitXY"
        />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />
    <ImageButton 
        android:id="@+id/test_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/btn_arrow"
        android:layout_marginLeft="100dp"
        android:layout_marginTop="200dp"
        android:onClick="onClick"
        />
     <com.google.ads.AdView android:id="@+id/adView"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         ads:adUnitId="b14be806e9ddf1f"
                         ads:adSize="BANNER"
                         ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
                         ads:loadAdOnCreate="true"/>

</RelativeLayout>

hello android Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.manny.HelloAndroid"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="7" 
        android:targetSdkVersion="13"/>

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" 
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
        <activity
            android:name=".HelloAndroid"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".HelloPage2">
        </activity>
    <activity android:name="com.google.ads.AdActivity"
                    android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|s    mallestScreenSize"/>
  </application>
  <uses-permission android:name="android.permission.INTERNET"/>
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
</manifest>

logcat output:

05-09 13:12:00.859: D/dalvikvm(24278): GC_EXTERNAL_ALLOC freed 51K, 44% free 3054K/5379K, external 2357K/2773K, paused 94ms
05-09 13:12:00.937: D/dalvikvm(24278): GC_EXTERNAL_ALLOC freed 1K, 44% free 3053K/5379K, external 3857K/4816K, paused 31ms
05-09 13:12:01.085: D/AndroidRuntime(24278): Shutting down VM
05-09 13:12:01.085: W/dalvikvm(24278): threadid=1: thread exiting with uncaught exception (group=0x4001e560)
05-09 13:12:01.109: E/AndroidRuntime(24278): FATAL EXCEPTION: main
05-09 13:12:01.109: E/AndroidRuntime(24278): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.manny.HelloAndroid/com.manny.HelloAndroid.HelloAndroid}: android.view.InflateException: Binary XML file line #30: Error inflating class com.google.ads.AdView
05-09 13:12:01.109: E/AndroidRuntime(24278):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1702)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1722)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at android.app.ActivityThread.access$1500(ActivityThread.java:124)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:974)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at android.os.Looper.loop(Looper.java:130)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at android.app.ActivityThread.main(ActivityThread.java:3821)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at java.lang.reflect.Method.invokeNative(Native Method)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at java.lang.reflect.Method.invoke(Method.java:507)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at dalvik.system.NativeStart.main(Native Method)
05-09 13:12:01.109: E/AndroidRuntime(24278): Caused by: android.view.InflateException: Binary XML file line #30: Error inflating class com.google.ads.AdView
05-09 13:12:01.109: E/AndroidRuntime(24278):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:253)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at android.app.Activity.setContentView(Activity.java:1716)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at com.manny.HelloAndroid.HelloAndroid.onCreate(HelloAndroid.java:17)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1666)
05-09 13:12:01.109: E/AndroidRuntime(24278):    ... 11 more
05-09 13:12:01.109: E/AndroidRuntime(24278): Caused by: java.lang.ClassNotFoundException: com.google.ads.AdView in loader dalvik.system.PathClassLoader[/data/app/com.manny.HelloAndroid-2.apk]
05-09 13:12:01.109: E/AndroidRuntime(24278):    at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at android.view.LayoutInflater.createView(LayoutInflater.java:471)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
05-09 13:12:01.109: E/AndroidRuntime(24278):    ... 20 more
05-09 13:12:11.593: I/Process(24278): Sending signal. PID: 24278 SIG: 9

I am using GoogleAdMobAdsSdkAndroid-6.0.0. Again I am very new to this and I have tried using examples off multiple sites but the app continues to crash when it hits a page with admob in it. If someone can help me it would be much appreciated. Thank you. If more code is needed let me know.

I’m using new Android Studio. I’ve done an application and works fine, now I’ve to add AdMob sdk. so I put the jar in ‘libs’ folder and right-click «add as library».
I run the project on my smartphone but the application crashes on startup.

How can i solve this? I think it’ll be something wrong with the import of AdMob sdk.

Thank you!

This is the xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.my.application"
android:installLocation="preferExternal"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="16" />

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

<application
    android:allowBackup="true"
    android:icon="@drawable/icon"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        //MY ACTIVITY
    </activity>
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

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

    <meta-data android:name="ADMOB_ALLOW_LOCATION_FOR_ADS" android:value="true"/>
    <meta-data android:name="ADMOB_PUBLISHER_ID" android:value="a151964f48b17a7"/>

</application>

This is the layout xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="match_parent"

            xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
            tools:context=".MainActivity">

<com.google.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        ads:adSize="BANNER"
        ads:adUnitId="MY_UNIT_ID"
        ads:loadAdOnCreate="true" >
</com.google.ads.AdView>

And this is the logcat

5-20 15:38:00.835  26121-26121/com.mnt.crudelibestmoments     E/AndroidRuntime: FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mnt.crudelibestmoments/com.mnt.crudelibestmoments.MainActivity}: android.view.InflateException: Binary XML file line #195: Error inflating class com.google.ads.AdView
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1967)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
    at android.app.ActivityThread.access$600(ActivityThread.java:127)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4448)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
    at dalvik.system.NativeStart.main(Native Method)
    Caused by: android.view.InflateException: Binary XML file line #195: Error inflating class com.google.ads.AdView
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:255)
    at android.app.Activity.setContentView(Activity.java:1835)
    at com.mnt.crudelibestmoments.MainActivity.onCreate(MainActivity.java:40)
    at android.app.Activity.performCreate(Activity.java:4465)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
    ... 11 more
    Caused by: java.lang.ClassNotFoundException: com.google.ads.AdView
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
    at android.view.LayoutInflater.createView(LayoutInflater.java:552)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)

If i hide the AdMob code in layout xml, the application works properly

thank you!

asked May 20, 2013 at 12:30

Nerd's user avatar

NerdNerd

1751 gold badge3 silver badges8 bronze badges

2

it’s a bit tricky but here is the solution:

The current preview release doesn’t edit the build.gradle file, even if you have added the admob library to the dependencies in the menu.
What you can do is to add the dependency manually, it’s very easy:

double click on the file «build.gradle» on the left in the navigation menu.
Add the following line:

compile files(‘libs/GoogleAdMobAdsSdk-6.4.1.jar’)

It should look like:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.4'

    }
}
apply plugin: 'android'

dependencies {
    compile files('libs/android-support-v4.jar')
    compile files('libs/GoogleAdMobAdsSdk-6.4.1.jar')
}

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    defaultConfig {
        minSdkVersion 7
        targetSdkVersion 16
    }
}

answered Jun 12, 2013 at 15:18

Chris623's user avatar

Chris623Chris623

2,4541 gold badge22 silver badges29 bronze badges

1

Right click your project and go to Properties -> Java Build Path. In Libraries add the AdMob SDK jar, and in Order and Export check the AdMob SDK library. Then clean and re-run your application.

Previously, putting 3rd party libraries in the libs/ folder was sufficient for the Android build to bundle these libraries when compiling your app. But since the release of v22 of the Android tools, you now have to explicitly add the library to your build path and export it.

answered May 24, 2013 at 15:29

Eric Leichtenschlag's user avatar

3

I was the same and achieve fix, I have done just the same as you and I miss you just do the following:

open a terminal (windows or linux) and go to the root of your project, eg AndroidStudioProjects / MyProject

Run the command:

Linux(is the file gradlew): ./gradlew clean

Windows(is the file gradlew.bat): gradlew clean

Now goto: Build > Rebuild Project

That’s it, enjoy!!!

Sorry for the bad English

answered May 30, 2013 at 21:25

picharras's user avatar

0

I got same problem.I changed Android.jar to 4.2.2. Now it works fine in both emulator and phone

answered Sep 26, 2013 at 12:09

GaneshKumar's user avatar

This may help you integrate admob with your application but google is not going to accept any updated or new apps which use this type of admob integration following 1 August 2014.

https://developers.google.com/mobile-ads-sdk/download#downloadandroid

Instead I recommend you to use Google Play Services version as suggested in above document.

answered Jan 26, 2014 at 21:17

gurkan's user avatar

gurkangurkan

3,4173 gold badges25 silver badges36 bronze badges

You are most likely using a AdView layout with package name com.google.ads.AdView. Change it to:

 <com.google.android.gms.ads.AdView
        xmlns:googleads="http://schemas.android.com/apk/lib/com.google.ads"
        android:id="@+id/ad"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"

        />

I am also using Android Studio, with build.gradle dependency set like this:

dependencies {
compile 'com.android.support:appcompat-v7:+'
compile 'com.google.android.gms:play-services:4.3.23'
}

Moving forward,we are not required to manually add libs that already have Maven coordinates to point to, so do NOT do this.

dependencies {
compile files('libs/android-support-v4.jar')
compile files('libs/GoogleAdMobAdsSdk-6.4.1.jar')
}

answered May 17, 2014 at 21:54

Chinedu's user avatar

User80353 posted

I am trying to inflate an AdView that is contained in a layout.xml file. When I try to do so, I get the following Android.Views.InflateException:
Binary XML file line #1: Error inflating class com.google.ads.AdView

Here is my layout XML file:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:minWidth="25px"
    android:minHeight="25px"
    android:padding="8dp">

    <com.google.ads.AdView
        xmlns:googleads="http://schemas.android.com/apk/lib/com.google.ads"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/slideshowListAdView"
        android:layout_weight="1"
        googleads:adSize="BANNER"
        googleads:adUnitId="@string/admob_bottom_banner_id"/>
</LinearLayout>

I’m going off several resources, including MonoDroid AdMob Test.

I have both Xamarin Components added to my project: Google Play Services, InAppBilling. I can access the Android.Gms.Ads namespace, including the AdView class. I just cannot inflate these views from a XML file which is what I want. I really do not want to have to generate these programatically…

EDIT: The solution was to change the XML to com.google.android.gms.ads.AdView instead. The one combination I didn’t try…

Hello,

I have included this project (and also the four dependences) in my workspace.
Compiled the libraries and included in my app, but the app refuses to run due to the AdView class is not defined.

The app is working fine with the 8.29 version of the Google Play Services (the last version that G has relased to be used with Eclipse)

Do you know what’s the issue?

Thanks

11-22 18:35:29.422 2760 2760 E AndroidRuntime: Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class com.google.android.gms.ads.AdView
11-22 18:35:29.422 2760 2760 E AndroidRuntime: at android.view.LayoutInflater.createView(LayoutInflater.java:645)
11-22 18:35:29.422 2760 2760 E AndroidRuntime: at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)
11-22 18:35:29.422 2760 2760 E AndroidRuntime: at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
11-22 18:35:29.422 2760 2760 E AndroidRuntime: at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
11-22 18:35:29.422 2760 2760 E AndroidRuntime: at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
11-22 18:35:29.422 2760 2760 E AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:515)

Member Avatar

8 Years Ago

using: eclipse

I have created a android app and I am trying to add some ads on to it. I am using admob.com but I am not sure what I am doing wrong. First here is error I am getting:

——-

ERROR:

——-

    08-27 23:09:03.650: E/AndroidRuntime(26340): FATAL EXCEPTION: main
    08-27 23:09:03.650: E/AndroidRuntime(26340): Process: com.g.tictactoe, PID: 26340
    08-27 23:09:03.650: E/AndroidRuntime(26340): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.g.tictactoe/com.gemini.bh.Splash}: android.view.InflateException: Binary XML file line #7: Error inflating class com.google.ads.AdView
    08-27 23:09:03.650: E/AndroidRuntime(26340):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2328)
    08-27 23:09:03.650: E/AndroidRuntime(26340):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2386)
    08-27 23:09:03.650: E/AndroidRuntime(26340):    at android.app.ActivityThread.access$900(ActivityThread.java:169)
    08-27 23:09:03.650: E/AndroidRuntime(26340):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1277)
    08-27 23:09:03.650: E/AndroidRuntime(26340):    at android.os.Handler.dispatchMessage(Handler.java:102)
    08-27 23:09:03.650: E/AndroidRuntime(26340):    at android.os.Looper.loop(Looper.java:136)
    08-27 23:09:03.650: E/AndroidRuntime(26340):    at android.app.ActivityThread.main(ActivityThread.java:5476)
    08-27 23:09:03.650: E/AndroidRuntime(26340):    at java.lang.reflect.Method.invokeNative(Native Method)
    08-27 23:09:03.650: E/AndroidRuntime(26340):    at java.lang.reflect.Method.invoke(Method.java:515)
    08-27 23:09:03.650: E/AndroidRuntime(26340):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
    08-27 23:09:03.650: E/AndroidRuntime(26340):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
    08-27 23:09:03.650: E/AndroidRuntime(26340):    at dalvik.system.NativeStart.main(Native Method)
    08-27 23:09:03.650: E/AndroidRuntime(26340): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class com.google.ads.AdView
    08-27 23:09:03.650: E/AndroidRuntime(26340):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
    08-27 23:09:03.650: E/AndroidRuntime(26340):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
    08-27 23:09:03.650: E/AndroidRuntime(26340):    at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
    08-27 23:09:03.650: E/AndroidRuntime(26340):    at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
    08-27 23:09:03.650: E/AndroidRuntime(26340):    at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
    08-27 23:09:03.650: E/AndroidRuntime(26340):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:366)
    08-27 23:09:03.650: E/AndroidRuntime(26340):    at android.app.Activity.setContentView(Activity.java:2031)
    08-27 23:09:03.650: E/AndroidRuntime(26340):    at com.g.bh.Splash.onCreate(Splash.java:19)
    08-27 23:09:03.650: E/AndroidRuntime(26340):    at android.app.Activity.performCreate(Activity.java:5451)
    08-27 23:09:03.650: E/AndroidRuntime(26340):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
    08-27 23:09:03.650: E/AndroidRuntime(26340):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292)
    08-27 23:09:03.650: E/AndroidRuntime(26340):    ... 11 more
    08-27 23:09:03.650: E/AndroidRuntime(26340): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.ads.AdView" on path: DexPathList[[zip file "/data/app/com.g.tictactoe-15.apk"],nativeLibraryDirectories=[/data/app-lib/com.gemini.g-15, /vendor/lib, /system/lib]]
    08-27 23:09:03.650: E/AndroidRuntime(26340):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
    08-27 23:09:03.650: E/AndroidRuntime(26340):    at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
    08-27 23:09:03.650: E/AndroidRuntime(26340):    at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
    08-27 23:09:03.650: E/AndroidRuntime(26340):    at android.view.LayoutInflater.createView(LayoutInflater.java:565)
    08-27 23:09:03.650: E/AndroidRuntime(26340):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)
    08-27 23:09:03.650: E/AndroidRuntime(26340):    ... 21 more

1st thing I did was downloaded «google Play Services for Froyo» from my eclipse android sdk manager. Than I added «google-play-services.jar» in to «Referenced Libraries» in eclipse project.

#------------------------------------------------------
# 2nd thing I did was to add ad on my layout xml file
# res > layout > mainXmlFile       
#-------------------------------------------------------





    <com.google.ads.AdView
        xmlns:ads = "http://schemas.android.com/apk/lib/com.google.ads"
            android:id = "@+id/adView"
            android:layout_width = "fill_parent"
            android:layout_height = "wrap_content"
            ads:adUnitId = "ci-apa-pab-44_myKey"
            ads:adSize = "BANNER"
            ads:testDevices = "TEST_EMULATOR, "
            ads:loadAdOnCreate = "true" />











#------------------------------------------
# Lastly I add permission in manifest file 
#AndroidManifest
#-------------------------------------------




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

Hello I am new to android dev and admob. I am trying to make a simple test app with a button, a couple pages and admob at the bottom. Everything works fine until I try implementing admob. Here is my code:

HelloAndroid.java:

package com.manny.HelloAndroid;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

public class HelloAndroid extends Activity {
    /** Called when the activity is first created. */
    private static final int ACTIVITY_CREATE = 0;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        setContentView(R.layout.main);
        ImageView image = (ImageView) findViewById(R.id.test_image);
        //image.setScaleType(ImageView.ScaleType.FIT_XY);

    }
    public void onClick(View v){
        Intent i = new Intent(this, HelloPage2.class);
        startActivityForResult(i, ACTIVITY_CREATE);
    }
}

main.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ImageView 
        android:id="@+id/test_image"
        android:src="@drawable/bak_vert_480x800"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:scaleType="fitXY"
        />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />
    <ImageButton 
        android:id="@+id/test_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/btn_arrow"
        android:layout_marginLeft="100dp"
        android:layout_marginTop="200dp"
        android:onClick="onClick"
        />
     <com.google.ads.AdView android:id="@+id/adView"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         ads:adUnitId="b14be806e9ddf1f"
                         ads:adSize="BANNER"
                         ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
                         ads:loadAdOnCreate="true"/>

</RelativeLayout>

hello android Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.manny.HelloAndroid"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="7" 
        android:targetSdkVersion="13"/>

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" 
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
        <activity
            android:name=".HelloAndroid"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".HelloPage2">
        </activity>
    <activity android:name="com.google.ads.AdActivity"
                    android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|s    mallestScreenSize"/>
  </application>
  <uses-permission android:name="android.permission.INTERNET"/>
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
</manifest>

logcat output:

05-09 13:12:00.859: D/dalvikvm(24278): GC_EXTERNAL_ALLOC freed 51K, 44% free 3054K/5379K, external 2357K/2773K, paused 94ms
05-09 13:12:00.937: D/dalvikvm(24278): GC_EXTERNAL_ALLOC freed 1K, 44% free 3053K/5379K, external 3857K/4816K, paused 31ms
05-09 13:12:01.085: D/AndroidRuntime(24278): Shutting down VM
05-09 13:12:01.085: W/dalvikvm(24278): threadid=1: thread exiting with uncaught exception (group=0x4001e560)
05-09 13:12:01.109: E/AndroidRuntime(24278): FATAL EXCEPTION: main
05-09 13:12:01.109: E/AndroidRuntime(24278): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.manny.HelloAndroid/com.manny.HelloAndroid.HelloAndroid}: android.view.InflateException: Binary XML file line #30: Error inflating class com.google.ads.AdView
05-09 13:12:01.109: E/AndroidRuntime(24278):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1702)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1722)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at android.app.ActivityThread.access$1500(ActivityThread.java:124)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:974)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at android.os.Looper.loop(Looper.java:130)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at android.app.ActivityThread.main(ActivityThread.java:3821)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at java.lang.reflect.Method.invokeNative(Native Method)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at java.lang.reflect.Method.invoke(Method.java:507)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at dalvik.system.NativeStart.main(Native Method)
05-09 13:12:01.109: E/AndroidRuntime(24278): Caused by: android.view.InflateException: Binary XML file line #30: Error inflating class com.google.ads.AdView
05-09 13:12:01.109: E/AndroidRuntime(24278):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:253)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at android.app.Activity.setContentView(Activity.java:1716)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at com.manny.HelloAndroid.HelloAndroid.onCreate(HelloAndroid.java:17)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1666)
05-09 13:12:01.109: E/AndroidRuntime(24278):    ... 11 more
05-09 13:12:01.109: E/AndroidRuntime(24278): Caused by: java.lang.ClassNotFoundException: com.google.ads.AdView in loader dalvik.system.PathClassLoader[/data/app/com.manny.HelloAndroid-2.apk]
05-09 13:12:01.109: E/AndroidRuntime(24278):    at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at android.view.LayoutInflater.createView(LayoutInflater.java:471)
05-09 13:12:01.109: E/AndroidRuntime(24278):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
05-09 13:12:01.109: E/AndroidRuntime(24278):    ... 20 more
05-09 13:12:11.593: I/Process(24278): Sending signal. PID: 24278 SIG: 9

I am using GoogleAdMobAdsSdkAndroid-6.0.0. Again I am very new to this and I have tried using examples off multiple sites but the app continues to crash when it hits a page with admob in it. If someone can help me it would be much appreciated. Thank you. If more code is needed let me know.

Have you recently updated your Android Tools to r17 or higher? If so, you need to create a libs/ folder in your project, and physically put the SDK in the project. Or, in the Java Build Path, you must Order and Export the SDK jar.

Otherwise, the jar doesn’t get included when your apk gets compiled, and all hell breaks loose when you run AdMob code at runtime.

NOTE: This applies to any library your project references.

You need to change the api. You can follow the official migration guide

Basically, you need to make the changes below:

Change:

<com.google.ads.AdView
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:id="@+id/adView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    ads:adUnitId="MY_AD_UNIT_ID"
    ads:adSize="BANNER"
    ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
    ads:loadAdOnCreate="true"/>

To:

<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:adUnitId="MY_AD_UNIT_ID"
    ads:adSize="BANNER"/>


// Java code required.
// testDevices and loadAdOnCreate attributes are
// no longer available.
AdView adView = (AdView)this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
    .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
    .addTestDevice("TEST_DEVICE_ID")
    .build();
adView.loadAd(adRequest);

Change:

<activity android:name="com.google.ads.AdActivity"/>

To:

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

Add:

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

Don’t forget the permissions:

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

#android #android-gradle-plugin #admob

#Android #android-gradle-плагин #admob

Вопрос:

когда я пытаюсь запустить свое приложение на своем устройстве, приложение выходит из строя, и я получаю эту ошибку:

 android.view.InflateException: Binary XML file line #9: Error inflating class com.google.ads.AdView
 

я уже пытаюсь использовать решения, предложенные в stackoverflow, но это не работает с этой ошибкой.

файл build.gradle (включая зависимости)

 apply plugin: 'com.android.application'

android {
    compileSdkVersion 'Google Inc.:Google APIs:16'
    buildToolsVersion '21.1.2'

    defaultConfig {
        applicationId "com.recipes.app"
        minSdkVersion 9
        targetSdkVersion 9
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_5
            targetCompatibility JavaVersion.VERSION_1_5
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.google.android.gms:play-services-ads:8.3.0'
}
 

Ответ №1:

com.google.ads.AdView это имя пакета, использовавшееся до интеграции SDK для мобильной рекламы с сервисами Google Play. Попробуйте вместо этого использовать текущий, com.google.android.gms.ads.AdView , в своих макетах.

Понравилась статья? Поделить с друзьями:
  • Error inflating class androidx fragment app fragmentcontainerview
  • Error inflate data stream error unknown compression method
  • Error inflate data stream error incorrect header check
  • Error indirection requires pointer operand int invalid
  • Error indexing must appear last in an index expression