admob 停止工作 [ 在无法接收广告(无效的广告请求)上



广告(智能横幅admob)最近在我的应用程序中消失了,尽管它们以前工作正常。

使用virtual deviceEclipse中运行应用时显示以下消息:

上 接收广告失败(广告请求无效。

当我打开我的main.xml文件时,显示此错误消息:

为标记线性布局找到意外的命名空间前缀"xmlns"

文件

主.xml

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/fullwrapper"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="#5a4872" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/container"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:orientation="vertical"
    android:background="#5a4872" >
      
         <LinearLayout
        	android:id="@+id/splash"
        	android:layout_width="fill_parent"
        	android:layout_height="fill_parent"
        	android:background="@drawable/splashscreen"
        	android:gravity="center_horizontal|center_vertical"
        	android:orientation="vertical" >
            <Button
                android:id="@+id/button_play"
                android:background="@drawable/btn_gameplay"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:gravity="center_horizontal|center_vertical"
                android:orientation="horizontal"
                android:text="@string/button_play"
                android:textColor="#ffffff"
                android:textStyle="bold"
                android:textSize="25.0sp" />
            <ImageView
                android:id="@+id/image_splash"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/appname"
                android:gravity="center_horizontal" />
            
		 </LinearLayout>
    <view
        android:id="@+id/gridview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        class="maazbah.memory.game.kids.ui.MemoryGridView"
        android:gravity="center"
        android:horizontalSpacing="8dp"
        android:layoutAnimation="@anim/layout_random_fade"
        android:numColumns="4"
        android:stretchMode="columnWidth"
        android:verticalSpacing="8dp"
        android:visibility="gone" />
</LinearLayout>
<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="wrap_content"
    android:layout_gravity="bottom"
    android:gravity="center" >
<com.google.ads.AdView android:id="@+id/adView"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         ads:adUnitId="@string/banner_ad_unit_id"
                         ads:adSize="BANNER"
                         ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
                         ads:loadAdOnCreate="true"
                        />
</LinearLayout>
</LinearLayout>

安卓清单.xml

<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          android:versionCode="1"
          android:versionName="1.0"
          android:installLocation="auto"
          package="maazbah.memory.game.kids">
    <uses-sdk android:minSdkVersion="4" android:targetSdkVersion="15" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <application android:icon="@drawable/icon"
                android:label="@string/app_name"
                android:logo="@drawable/logo"
                android:hardwareAccelerated="true">
        <activity android:name="maazbah.memory.game.kids.ui.MainActivity" 
            	  android:screenOrientation="portrait"
            	  android:label="@string/activity_title" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <activity android:name="maazbah.memory.game.kids.ui.PreferencesActivity"
            	  android:screenOrientation="portrait"	
                  android:label="@string/activity_title" >
        </activity>
                <activity android:name="com.google.ads.AdActivity"
                  android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
    </application>
</manifest>

主要活动.java

package maazbah.memory.game.kids.ui;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.media.AudioManager;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.DecelerateInterpolator;
import android.widget.Button;
import android.widget.ImageView;
import maazbah.memory.game.kids.Constants;
import maazbah.memory.game.kids.PreferencesService;
import maazbah.memory.game.kids.R;
import maazbah.memory.game.kids.Rotate3dAnimation;
import org.androidsoft.utils.sound.SoundManager;
/**
 * AbstractMainActivity
 */
public abstract class AbstractMainActivity extends Activity implements OnClickListener
{
    private static final String PREF_STARTED = "started";
    private static final int SOUND_NEW_GAME = 1000;
    private static final int SPLASH_SCREEN_ROTATION_COUNT = 2;
    private static final int SPLASH_SCREEN_ROTATION_DURATION = 2000;
    private static final int GAME_SCREEN_ROTATION_COUNT = 2;
    private static final int GAME_SCREEN_ROTATION_DURATION = 2000;
    private static final String KEY_VERSION = "version";
    private static final int DEFAULT_VERSION = 1;  // should be set to 0 after 1.4
    protected boolean mQuit;
    private ViewGroup mContainer;
    private View mSplash;
    private Button mButtonPlay;
    private boolean mStarted;
    protected abstract View getGameView();
    protected abstract void newGame();
    protected abstract void preferences();
    
    /**
     * {@inheritDoc }
     */
    @Override
    public void onCreate(Bundle icicle)
    {
        super.onCreate(icicle);
        setVolumeControlStream(AudioManager.STREAM_MUSIC);        
        SoundManager.init(AbstractMainActivity.this);
        setContentView(R.layout.main);
        mContainer = (ViewGroup) findViewById(R.id.container);
        mSplash = (View) findViewById(R.id.splash);
        mButtonPlay = (Button) findViewById(R.id.button_play);
        mButtonPlay.setOnClickListener(this);
        checkLastVersion();
    }
    /**
     * {@inheritDoc }
     */
    @Override
    protected void onResume()
    {
        super.onResume();
        SharedPreferences prefs = getPreferences(0);
        mStarted = prefs.getBoolean(PREF_STARTED, false);
        if (mStarted)
        {
            mSplash.setVisibility(View.GONE);
            getGameView().setVisibility(View.VISIBLE);
        } else
        {
            mSplash.setVisibility(View.VISIBLE);
            getGameView().setVisibility(View.GONE);
        }
        if (!SoundManager.isInitialized())
        {
            SoundManager.init(this);
        }
        SoundManager.instance().addSound(SOUND_NEW_GAME, R.raw.start_game);
    }
    /**
     * {@inheritDoc }
     */
    @Override
    protected void onPause()
    {
        super.onPause();
        SharedPreferences.Editor editor = getPreferences(0).edit();
        if (!mQuit)
        {
            editor.putBoolean(PREF_STARTED, mStarted);
        } else
        {
            editor.remove(PREF_STARTED);
        }
        editor.commit();
        SoundManager.release();
    }
    /**
     * {@inheritDoc }
     */
    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu, menu);
        return true;
    }
    /**
     * {@inheritDoc }
     */
    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
        switch (item.getItemId())
        {
            case R.id.menu_new:
                onNewGame();
                return true;
            case R.id.menu_quit:
                quit();
                return true;
            case R.id.menu_preferences:
                preferences();
                return true;
        }
        return false;
    }
    private void onNewGame()
    {
        if( PreferencesService.instance().isSoundEnabled() )
        {
            SoundManager.instance().playSound(SOUND_NEW_GAME);
        }
        newGame();
    }
    /**
     * Quit the application
     */
    void quit()
    {
        mQuit = true;
        AbstractMainActivity.this.finish();
    }
    /**
     * {@inheritDoc }
     */
    public void onClick(View v)
    {
        if (v == mButtonPlay)
        {
            applyRotation(0, SPLASH_SCREEN_ROTATION_COUNT * 360);
        }
    }
    protected void showEndDialog(String title, String message, int icon)
    {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(title);
        builder.setIcon(icon);
        builder.setMessage(message);
        builder.setCancelable(false);
        builder.setPositiveButton(getString(R.string.new_game),
                new DialogInterface.OnClickListener()
                {
                    public void onClick(DialogInterface dialog, int id)
                    {
                        dialog.cancel();
                        onNewGame();
                    }
                });
        builder.setNegativeButton(getString(R.string.quit),
                new DialogInterface.OnClickListener()
                {
                    public void onClick(DialogInterface dialog, int id)
                    {
                        quit();
                    }
                });
        AlertDialog alert = builder.create();
        alert.show();
    }
    // 3D anim from Splash Screen to Game screen
    /**
     * Setup a new 3D rotation on the container view.
     *
     * @param start the start angle at which the rotation must begin
     * @param end the end angle of the rotation
     */
    private void applyRotation(float start, float end)
    {
        // Find the center of the container
        final float centerX = mContainer.getWidth() / 2.0f;
        final float centerY = mContainer.getHeight() / 2.0f;
        // Create a new 3D rotation with the supplied parameter
        // The animation listener is used to trigger the next animation
        final Rotate3dAnimation rotation =
                new Rotate3dAnimation(start, end, centerX, centerY, 310.0f, true);
        rotation.setDuration(SPLASH_SCREEN_ROTATION_DURATION);
        rotation.setFillAfter(true);
        rotation.setInterpolator(new AccelerateInterpolator());
        rotation.setAnimationListener(new DisplayNextView());
        mContainer.startAnimation(rotation);
    }
    /**
     * This class listens for the end of the first half of the animation.
     * It then posts a new action that effectively swaps the views when the container
     * is rotated 90 degrees and thus invisible.
     */
    private final class DisplayNextView implements Animation.AnimationListener
    {
        private DisplayNextView()
        {
        }
        public void onAnimationStart(Animation animation)
        {
            if( PreferencesService.instance().isSoundEnabled() )
            {
                SoundManager.instance().playSound(SOUND_NEW_GAME);
            }
        }
        public void onAnimationEnd(Animation animation)
        {
            mContainer.post(new SwapViews());
        }
        public void onAnimationRepeat(Animation animation)
        {
        }
    }
    /**
     * This class is responsible for swapping the views and start the second
     * half of the animation.
     */
    private final class SwapViews implements Runnable
    {
        public void run()
        {
            final float centerX = mContainer.getWidth() / 2.0f;
            final float centerY = mContainer.getHeight() / 2.0f;
            Rotate3dAnimation rotation;
            mSplash.setVisibility(View.GONE);
            getGameView().setVisibility(View.VISIBLE);
            getGameView().requestFocus();
            rotation = new Rotate3dAnimation(0, 360 * GAME_SCREEN_ROTATION_COUNT, centerX, centerY, 310.0f, false);
            rotation.setDuration(GAME_SCREEN_ROTATION_DURATION);
            rotation.setFillAfter(true);
            rotation.setInterpolator(new DecelerateInterpolator());
            mContainer.startAnimation(rotation);
            mStarted = true;
        }
    }
    private void checkLastVersion()
    {
        int resTitle;
        int resMessage;
        final int lastVersion = getVersion();
        if (lastVersion < Constants.VERSION)
        {
            if (lastVersion == 0)
            {
                // This is a new install
                resTitle = R.string.first_run_dialog_title;
                resMessage = R.string.first_run_dialog_message;
            } else
            {
                // This is an upgrade.
                resTitle = R.string.whats_new_dialog_title;
                resMessage = R.string.whats_new_dialog_message;
            }
            // show what's new message
            saveVersion(Constants.VERSION);
            showWhatsNewDialog(resTitle, resMessage, R.drawable.icon);
        }
    }
    private int getVersion()
    {
        SharedPreferences prefs = getSharedPreferences(AbstractMainActivity.class.getName(), Activity.MODE_PRIVATE);
        return prefs.getInt(KEY_VERSION, DEFAULT_VERSION);
    }
    private void saveVersion(int version)
    {
        SharedPreferences prefs = getSharedPreferences(AbstractMainActivity.class.getName(), Activity.MODE_PRIVATE);
        Editor editor = prefs.edit();
        editor.putInt(KEY_VERSION, version);
        editor.commit();
    }
    protected void showWhatsNewDialog(int title, int message, int icon)
    {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(title);
        builder.setIcon(icon);
        builder.setMessage(message);
        builder.setPositiveButton(getString(R.string.ok),
                new DialogInterface.OnClickListener()
                {
                    public void onClick(DialogInterface dialog, int id)
                    {
                        dialog.cancel();
                        onNewGame();
                    }
                });
        AlertDialog alert = builder.create();
        alert.show();
    }
}

有谁知道我的代码出了什么问题?谢谢。

删除 xmlns:android="http://schemas.android.com/apk/res/android"嵌套的线性布局。仅将其保留在根 LinearLayout 中(第一个)。因为 Android 命名空间在 Android 中.xml文件应该只声明一次。

将 LinearLayout 中的广告命名空间更改为

        xmlns:ads="http://schemas.android.com/apk/res-auto"

感谢 Rebly 亲爱的 Shubham Shukla & Yupi,

我已经从嵌套线性布局中删除了这一行。

xmlns:android="http://schemas.android.com/apk/res/android"

并仅将其保留在根线性布局中,我将这条线移动到根线性布局。

xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"

文件(主.xml)它已变为:

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:id="@+id/fullwrapper"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="#5a4872" >
<LinearLayout 
    android:id="@+id/container"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:orientation="vertical"
    android:background="#5a4872" >
      
         <LinearLayout
        	android:id="@+id/splash"
        	android:layout_width="fill_parent"
        	android:layout_height="fill_parent"
        	android:background="@drawable/splashscreen"
        	android:gravity="center_horizontal|center_vertical"
        	android:orientation="vertical" >
            <Button
                android:id="@+id/button_play"
                android:background="@drawable/btn_gameplay"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:gravity="center_horizontal|center_vertical"
                android:orientation="horizontal"
                android:text="@string/button_play"
                android:textColor="#ffffff"
                android:textStyle="bold"
                android:textSize="25.0sp" />
            <ImageView
                android:id="@+id/image_splash"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/appname"
                android:gravity="center_horizontal" />
            
		 </LinearLayout>
    <view
        android:id="@+id/gridview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        class="maazbah.memory.game.kids.ui.MemoryGridView"
        android:gravity="center"
        android:horizontalSpacing="8dp"
        android:layoutAnimation="@anim/layout_random_fade"
        android:numColumns="4"
        android:stretchMode="columnWidth"
        android:verticalSpacing="8dp"
        android:visibility="gone" />
</LinearLayout>
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:gravity="center" >
<com.google.ads.AdView android:id="@+id/adView"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         ads:adUnitId="ca-app-pub-9321782199225340/4561186116"
                         ads:adSize="BANNER"
                         ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
                         ads:loadAdOnCreate="true"
                        />
</LinearLayout>
</LinearLayout>

以及在此修订后在日食中显示的新消息,

To get test ads on this device, call adRequest.addTestDevice("DDE8F001C78F8B58CE003B1327202313");

而 AdMob 横幅显示到现在 在此修正案之后!

最新更新