My AdMob banner is not showing in my android application. After seeing older questions about the same problem none helped because they refer to a previous version of android studio. Now some things have become deprecated.

My NewRecord.java file contatins the following code:

package com.example.anxietycalendar; import androidx.appcompat.app.AppCompatActivity; import android.content.Intent; import android.graphics.Color; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import com.akaita.android.circularseekbar.CircularSeekBar; import com.google.android.gms.ads.AdListener; import com.google.android.gms.ads.AdRequest; import com.google.android.gms.ads.AdView; import com.google.android.gms.ads.InterstitialAd; import com.google.android.gms.ads.MobileAds; import com.google.android.gms.ads.initialization.InitializationStatus; import com.google.android.gms.ads.initialization.OnInitializationCompleteListener; import java.text.DateFormat; import java.text.DecimalFormat; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; public class NewRecord extends AppCompatActivity {     DatabaseHelper myDB;     private Button Submit;     public float pr;     private AdView mAdView;     private InterstitialAd mInterstitialAd;     @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_new_record);         MobileAds.initialize(this, new OnInitializationCompleteListener() {             @Override             public void onInitializationComplete(InitializationStatus initializationStatus) {             }         });         mAdView = findViewById(R.id.adView);         AdRequest adRequest = new AdRequest.Builder().build();         mAdView.loadAd(adRequest);         mAdView.setAdListener(new AdListener() {                                   @Override                                   public void onAdFailedToLoad(int errorCode) {                                       String onAdFailedToLoad = null;                                       Log.d(onAdFailedToLoad, "This is why: " + errorCode);                                   }         });         myDB=new DatabaseHelper(this);         Submit= (Button) findViewById(R.id.submit);         CircularSeekBar seekBar = (CircularSeekBar) findViewById(R.id.seekbar);         seekBar.setProgressTextFormat(new DecimalFormat("###,###,###,##0.00"));         seekBar.setProgress(0);         seekBar.setRingColor(Color.GREEN);         seekBar.setOnCircularSeekBarChangeListener(new CircularSeekBar.OnCircularSeekBarChangeListener() {             @Override             public void onProgressChanged(CircularSeekBar seekBar, float progress, boolean fromUser) {                 if (progress < 5) {                     seekBar.setRingColor(Color.GREEN);                     pr = progress;                 } else if (progress < 8) {                     seekBar.setRingColor(Color.YELLOW);                     pr = progress;                 } else {                     seekBar.setRingColor(Color.RED);                     pr = progress;                 }             }             @Override             public void onStartTrackingTouch(CircularSeekBar seekBar) {             }             @Override             public void onStopTrackingTouch(CircularSeekBar seekBar) {             }         });         Submit.setOnClickListener(new View.OnClickListener() {             @Override             public void onClick(View v) {                 myDB.insertData(Math.round(pr));             }         });     } } 

While the activity_new_record.xml contains the following code:

<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:background="@drawable/background"     tools:context=".NewRecord">     <TextView         android:id="@+id/perctext"         android:layout_width="281dp"         android:layout_height="36dp"         android:layout_marginTop="36dp"         android:background="@drawable/bg_calen2"         android:ems="10"         android:gravity="center"         android:inputType="textPersonName"         android:text="How much stress do you feel?"         android:textColor="@color/white"         app:layout_constraintEnd_toEndOf="parent"         app:layout_constraintHorizontal_bias="0.43"         app:layout_constraintStart_toStartOf="parent"         app:layout_constraintTop_toTopOf="parent" />     <com.akaita.android.circularseekbar.CircularSeekBar         android:id="@+id/seekbar"         android:layout_width="300dp"         android:layout_height="224dp"         android:layout_marginTop="52dp"         app:enabled="true"         app:innerCircleColor="#e0f7e9"         app:layout_constraintHorizontal_bias="0.495"         app:layout_constraintLeft_toLeftOf="parent"         app:layout_constraintRight_toRightOf="parent"         app:layout_constraintTop_toBottomOf="@+id/perctext"         app:max="10"         app:min="0"         app:progress="1"         app:progressTextColor="@android:color/black"         app:progressTextSize="26"         app:ringColor="@color/colorAccent"         app:ringWidth="0.5"         app:showIndicator="true"         app:showInnerCircle="true"         app:showProgressText="true"         app:speedMultiplier="2" />     <Button         android:id="@+id/submit"         style="@style/BlueButton"         android:layout_width="271dp"         android:layout_height="31dp"         android:text="Submit Record"         app:layout_constraintBottom_toBottomOf="parent"         app:layout_constraintEnd_toEndOf="parent"         app:layout_constraintStart_toStartOf="parent"         app:layout_constraintTop_toBottomOf="@+id/seekbar"         app:layout_constraintVertical_bias="0.168" />     <com.google.android.gms.ads.AdView         android:id="@+id/adView"         xmlns:ads="http://schemas.android.com/apk/res-auto"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignParentBottom="true"         android:layout_centerHorizontal="true"         ads:adSize="BANNER"         ads:adUnitId="ca-app-pub-6417467530528623/7094248892"         ads:layout_constraintBottom_toBottomOf="parent"         ads:layout_constraintEnd_toEndOf="parent"         ads:layout_constraintHorizontal_bias="0.615"         ads:layout_constraintStart_toStartOf="parent"         ads:layout_constraintTop_toBottomOf="@+id/submit"         ads:layout_constraintVertical_bias="0.198" /> </androidx.constraintlayout.widget.ConstraintLayout> 

This is the activity where I am trying to add the banner app. I have tried to use the test ad unit Id's but it is still failing.

I would also like to add this part of the code of the AndroidManifest.xml:

<application         android:allowBackup="true"         android:icon="@mipmap/ic_launcher"         android:label="Anxiety Calendar"         android:roundIcon="@mipmap/ic_launcher_round"         android:supportsRtl="true"         android:theme="@style/AppTheme"         tools:replace="android:label">         <activity android:name=".Statistics"></activity>         <!-- Include the AdActivity configChanges and theme. -->         <activity             android:name="com.google.android.gms.ads.AdActivity"             android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"             android:theme="@android:style/Theme.Translucent" /> <!-- Sample AdMob App ID: ca-app-pub-3940256099942544~3347511713 -->         <meta-data             android:name="com.google.android.gms.ads.APPLICATION_ID"             android:value="ca-app-pub-6417467530528623~3872355031" /> 

How do I fix this? I have been trying for days... I am using a Galaxy Nexus API 22 simulator.

Tag:google-ads-api, android, java, google-maps, android-studio

2 comments.

  1. samurai

    have you add this on your gradle?

    dependencies { implementation 'com.google.android.gms:play-services-ads:19.0.0' }

    and

    String myid=getString(R.string.appid); MobileAds.initialize(this, myid); //myid is ca-app-pub-3940256099942544/6300978111 mAdView = findViewById(R.id.adView); AdRequest adRequest = new AdRequest.Builder().build(); mAdView.loadAd(adRequest); mAdView.setAdListener(new AdListener() { @Override public void onAdLoaded() { // Code to be executed when an ad finishes loading. } @Override public void onAdOpened() { // Code to be executed when an ad opens an overlay that // covers the screen. } });

    I think you forgot add this line

    String myid=getString(R.string.appid); MobileAds.initialize(this, myid);
    1. user12610369

      yes I have and the implementation of this is now version 19.0.0

Add a new comment.