2017-01-25 1 views
1

Anzeigen (Smart Banner admob) sind kürzlich in meiner Anwendung verschwunden, obwohl sie einfach gut funktionierten.admob funktioniert nicht mehr [auf Fehler beim Empfang der Anzeige (Ungültige Anzeigenanfrage)]

Die folgende Meldung wird angezeigt, wenn die App in Eclipse mit einem virtual device ausgeführt wird:

on Failed To Receive Ad(Invalid Ad request.)

Wenn ich meine main.xml Datei diese Fehlermeldung öffnen wird angezeigt:

Unexpected namespace prefix "xmlns" found for tag LinearLayout

Dateien:

main.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 
 
     \t android:id="@+id/splash" 
 
     \t android:layout_width="fill_parent" 
 
     \t android:layout_height="fill_parent" 
 
     \t android:background="@drawable/splashscreen" 
 
     \t android:gravity="center_horizontal|center_vertical" 
 
     \t 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" /> 
 
      
 
\t \t </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>

AndroidManifest.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" 
 
      \t android:screenOrientation="portrait" 
 
      \t 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" 
 
      \t android:screenOrientation="portrait" \t 
 
        android:label="@string/activity_title" > 
 
     </activity> 
 
       <activity android:name="com.google.ads.AdActivity" 
 
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/> 
 
    </application> 
 
</manifest>

MainActivity.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(); 
 

 
    } 
 
}

Weiß jemand, was mit meinem Code falsch? Danke.

Antwort

0

Entfernen Sie xmlns:android="http://schemas.android.com/apk/res/android" von verschachtelten LinearLayout. Behalte es nur im root LinearLayout (erster). Weil der Android-Namespace in Android.xml-Dateien nur einmal deklariert werden sollte.

+0

ich diese Linie entfernt und an der Wurzel halten, dann, Fehlermeldung Fehler angezeigt: Fehler bei der Analyse XML: ungebundenen Präfix –

0

Ihre Anzeigen Namespace in Linearlayout ändern zu

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

Kommentare sind nicht für längere Diskussion; Diese Konversation wurde [verschoben, um zu chatten] (http://chat.stackoverflow.com/rooms/134272/discussion-on-answer-by-shubham-shukla-admob-stopped-working-on-failed-to-rece) . –

0

Vielen Dank für Rebly lieber Shubham Shukla & Yupi,

ich diese Zeile aus verschachtelten Linearlayout gelöscht haben.

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

und halten Sie sie nur in root Linearlayout, und ich bewegen Sie diese Zeile Linearlayout zu verankern.

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

Die Datei (main.xml) Es hat sich:

<?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 
 
     \t android:id="@+id/splash" 
 
     \t android:layout_width="fill_parent" 
 
     \t android:layout_height="fill_parent" 
 
     \t android:background="@drawable/splashscreen" 
 
     \t android:gravity="center_horizontal|center_vertical" 
 
     \t 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" /> 
 
      
 
\t \t </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>

und neue Nachricht in eclips nach dieser Änderung gezeigt,

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

und die admob Banner dosent bis jetzt nach dieser Änderung angezeigt!

+0

jetzt funktioniert es? –

+0

Nein, bis jetzt! –

Verwandte Themen