2

Before writing this question I have checked various questions on Stack Overflow such as:

I have checked the spelling and it seems to be correct.

I also checked the targetSdkVersion is greater than Sdk13. Mine is set too

android:targetSdkVersion="15" />

I checked this question but I am not sure if this is the problem.

I have also consulted this particular url


package com.example.advert;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.LinearLayout;
import android.support.v4.app.NavUtils;
import com.google.ads.*;
public class MainActivity extends Activity {
    private AdView adView;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);



String MY_AD_UNIT_ID = "a15000820551daa";

 // Create the adView
    adView = new AdView(this, AdSize.BANNER, MY_AD_UNIT_ID);

    // Lookup your LinearLayout assuming it’s been given
    // the attribute android:id="@+id/mainLayout"
    LinearLayout layout = (LinearLayout)findViewById(R.id.mainLayout);

    // Add the adView to it
    layout.addView(adView);

    // Initiate a generic request to load it with an ad
    adView.loadAd(new AdRequest());





}

@Override
public void onDestroy() {
  if (adView != null) {
    adView.destroy();
  }
  super.onDestroy();
}




}

AndroidManifest.xml

 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.advert"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="10"
        android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main" >
            <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"

        ></activity>
    </application>

</manifest>

The error message that is returned is a black box where the add should be. And red writing which says You must have AdActivity declared in AndroidManifest.xml with configChanges

Community
  • 1
  • 1
alex
  • 398
  • 1
  • 6
  • 24

2 Answers2

6

Your missing android:configChanges attribute in AdActivity, like this:

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

Also your project needs to reference Android SDK 2.2 (API 8) and later.

azgolfer
  • 15,087
  • 4
  • 49
  • 46
  • I tried adding that line you mentioned but it says string errors not allowed at configchanges – alex Jul 15 '12 at 18:45
  • I tried the earlier version of ad mob 4.04 but that didn't fix the problem. – alex Jul 15 '12 at 20:17
  • What exactly was your problem? App crashed? No ads coming from admob? – azgolfer Jul 15 '12 at 21:01
  • Have you looked at https://developers.google.com/mobile-ads-sdk/docs/android/fundamentals ? They show the exact same tag I posted above. – azgolfer Jul 15 '12 at 22:27
  • error: Error: String types not allowed (at 'configChanges' with value 'keyboard|keyboardHidden|orientation| screenLayout|uiMode|screenSize|smallestScreenSize'). – alex Jul 15 '12 at 22:41
  • Make sure your project references Android SDK 2.2 or later. Right click on the project title, select 'Properties', then goto 'Android' item. – azgolfer Jul 15 '12 at 22:50
  • I went there and its sets too SDK 2.3.3 – alex Jul 16 '12 at 11:18
3

I fixed the problem it was where android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/> was being placed.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.admob"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="10"
        android:targetSdkVersion="15" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main" >
            <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" />
    </application>
 <uses-permission android:name="android.permission.INTERNET" />
   <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
alex
  • 398
  • 1
  • 6
  • 24