Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
207 views
in Technique[技术] by (71.8m points)

android - com.google.ads.AdView failed to instantiate

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...