1

I have used admob sdk and added as external jar.In xml i have specified

<LinearLayout 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">
<TextView android:id="@+id/headerfield"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
<ListView android:id="@+id/list"
    android:layout_width="fill_parent"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

<com.google.ads.AdView 
    android:id="@+id/ad"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    ads:adSize="BANNER"    
    ads:adUnitId="Publisher Id"
    ads:loadAdOnCreate="true" />    
</LinearLayout>

Manifest

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

But in graphical mode its giving me a error log:

com.google.ads.AdView - the following class could not be instantiated. 

Inside the program its showing

You must have AdActivity declared in AndroidManifest.xml with configChanges.

Eric Leichtenschlag
  • 8,881
  • 1
  • 28
  • 28
sidG
  • 49
  • 1
  • 1
  • 9
  • `` `
    ` ``
    – sidG May 04 '12 at 12:19
  • `` then after this is the adview specified inside the quesion then relativelayout is closed – sidG May 04 '12 at 12:28
  • Looks weird - is your AdView within the ListView? As becomputer suggests, posts the entire layout file in your question. – Michael A. May 04 '12 at 12:44
  • My layout is working allright inside the program where i have called the adView there its showing AdActivity should have configChanges declared in AndroidManifest even though i have written configChanges – sidG May 04 '12 at 13:24

3 Answers3

5

From the documentation, you'll need to include additional configChanges in your activity (assuming you're using 4.3.1 or higher):

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

If you run into issues where screenSize and smallestScreenSize aren't recognized, you'll have to compile aganist Android 3.2 or higher. Check out this migration blog post for more information on getting off of 4.1.1 to a newer version (the same applies to moving to 6.0.0 as well).

Eric Leichtenschlag
  • 8,881
  • 1
  • 28
  • 28
  • yes i have tried this one as well but whole statement is giving me error i have given three parameters the first three `keyboard|keyboardHidden|orientation`. Iguess i will try with higher target version. – sidG May 04 '12 at 15:53
  • 2
    You're probably getting an error because screenSize and smallestScreenSize config changes aren't recognized. They were only introduced in API 13, so you'll need to set target in project.properties to android-13 or higher to compile against a recent SDK. The SDK does not place any restrictions on the ` element, so you can still set the minSdkVersion and targetSdkVersion to whatever you'd like, and serve your app to those devices. – Eric Leichtenschlag May 04 '12 at 16:45
  • Eric's reply here is correct. Your problem is almost certainly that you are not compiling against a high enough API version. – Michael A. May 04 '12 at 19:56
  • Even though it says api level 13 in the documentation this error won't go away until I change to api level 15. No big deal though – Peter Jun 05 '12 at 21:18
2

Have you exported the AdMob library as well?

Go into Project Properties > Java Build Path > Order and Export

Check that the little box next to your admob.jar is checked; if not, do so.

Michael A.
  • 4,163
  • 3
  • 28
  • 47
0

In case someone is still viewing this thread- check if the API level you are rendering the view against is below 17. For me it worked at 17. You can change it by using the little droid just above your graphical layout.