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 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.


Solution 1:

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.

Solution 2:

For me it worked like this.

  • close eclipse
  • add manually the sdk ad jar file in your project's "libs" folder
  • open eclipse
  • refresh your project till the sdk jar appears on libs folder
  • go to your project's properties > Java Build Path > Library Tab and choose "add Jars" instead of an external one. and select the sdk from the list below.
  • go to "Order and Export" tab and select again the SDK
  • click ok AND ITS DONE.

Then just add the proper code in the manifest and the xml.

Solution 3:

I was experiencing this, too. The build path didn't seem to work no matter what I did. So I exited Eclipse, created a new libs folder in the workbench package directory. Added the GoogleAdMobAdsSdk-6.0.1.jar to that folder. I DID NOT add the whole SDK, just the jar file. Then restarted Eclipse. I had to refresh the project inspector column to show the changes I made outside of Eclipse. It showed the new libs folder and jar file, but it still didn't work... Then I right clicked on the new libs folder and set it as a SOURCE FOLDER. NOW EVERYTHING WORKS!

Im using Eclipse Version: Indigo Service Release 2 Build id: 20120216-1857

Android Development Tools 18.0.0.v201203301601-306762

It seems that maybe the tools are ahead of the documentation... or some kind of Eclipse bug.... Very aggravating!

Solution 4:

I had the same problem and noticed that ordering the export list is also important.
This is mine, this way it works:

enter image description here