My Admob Ad not showing in my app getting error code 3 "no ad config" how to fix it, also my test ad is working properly

Viewed 4106

//This is my Activity where i want to load my ad

import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
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.LoadAdError;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.initialization.InitializationStatus;
import com.google.android.gms.ads.initialization.OnInitializationCompleteListener;


public class TenaliRamanActivity extends AppCompatActivity {

    ListView listView;
    private InterstitialAd mInterstitialAd;
    private AdView mAdView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tenali_raman);

//AD Code Start

        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 onAdLoaded() {
                // Code to be executed when an ad finishes loading.
            }

// I am overriding onAdFailedToLoad() method to know why my ad is not showing and getting error code 3, message "no ad config"

            @Override
            public void onAdFailedToLoad(LoadAdError adError) {
                Toast.makeText(TenaliRamanActivity.this, " Banner AdError is "+ adError, 
 Toast.LENGTH_LONG).show();
                
            }

            @Override
            public void onAdOpened() {
                // Code to be executed when an ad opens an overlay that
                // covers the screen.
            }

            @Override
            public void onAdClicked() {
                // Code to be executed when the user clicks on an ad.
            }

            @Override
            public void onAdLeftApplication() {
                // Code to be executed when the user has left the app.
            }

            @Override
            public void onAdClosed() {
                // Code to be executed when the user is about to return
                // to the app after tapping on an ad.
            }
        });

// Interstitial code Start here

        mInterstitialAd = new InterstitialAd(this);
        mInterstitialAd.setAdUnitId("ca-app-pub-4745680273727033/3318988209");
        mInterstitialAd.loadAd(new AdRequest.Builder().build());

        mInterstitialAd.setAdListener(new AdListener() {
            @Override
            public void onAdLoaded() {
                // Code to be executed when an ad finishes loading.
            }

//I also Toasted the my Inetrstitial Ad error message and getting same error code 3, message "no ad config"[my error is this][1]

            **@Override
            public void onAdFailedToLoad(LoadAdError adError) {
                Toast.makeText(TenaliRamanActivity.this, " Instertial Ad Error is"+ adError, 

Toast.LENGTH_SHORT).show(); enter code here}**

            @Override
            public void onAdOpened() {
                // Code to be executed when the ad is displayed.
            }

            @Override
            public void onAdClicked() {
                // Code to be executed when the user clicks on an ad.
            }

            @Override
            public void onAdLeftApplication() {
                // Code to be executed when the user has left the app.
            }

            @Override
            public void onAdClosed() {
                // Code to be executed when the interstitial ad is closed.
            }
        });


       // Start Application Code
        listView= findViewById(R.id.listView);

        String[] tenaliRaman= getResources().getStringArray(R.array.tenaliRaman);

        ArrayAdapter<String> adapter= new ArrayAdapter<>(this,R.layout.row_item, R.id.rowText, tenaliRaman);

        listView.setAdapter(adapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (mInterstitialAd.isLoaded()) {
                    mInterstitialAd.show();
                } else {
                    Intent intent= new Intent(TenaliRamanActivity.this, StoryTenaliRaman.class);
                    intent.putExtra("storyPosition", position);
                    startActivity(intent);
                }



            }
        });

    }
}


  [1]: https://i.stack.imgur.com/rNFvv.png
2 Answers

For anyone with similar issue, this error also happens intermittently with google's demo ads: https://developers.google.com/admob/android/test-ads#demo_ad_units

In my case I was using the banner demo:

ca-app-pub-3940256099942544/6300978111

And after testing it multiple times it failed 50% of the time. Real ads are working since I can see the stats in admob dashboard, so this should be safe to ignore... I hope.

First Of All go to project-level build.gradle

allprojects {
    repositories {
        google()
    }
}

instead of google() use this

maven {
    url 'https://maven.google.com/'
    name 'Google'
}

Did you use Testing IDs ?

Now go to your manifest file

Make sure you added the INTERNET permission in your AndroidManifest.xml

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

And Also use test admob app id in your AndroidManifest.xml also

 <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-3940256099942544~3347511713"/>

Test AdMob app ID: ca-app-pub-3940256099942544~3347511713

The source for the Test Admob app ID

Then You can also find here the rest of Testing ids

App Open: ca-app-pub-3940256099942544/3419835294

Banner: ca-app-pub-3940256099942544/6300978111

Interstitial: ca-app-pub-3940256099942544/1033173712

Interstitial Video: ca-app-pub-3940256099942544/8691691433

Rewarded: ca-app-pub-3940256099942544/5224354917

Rewarded Interstitial: ca-app-pub-3940256099942544/5354046379

Native Advanced: ca-app-pub-3940256099942544/2247696110

Native Advanced Video: ca-app-pub-3940256099942544/1044960115

replace your ids with these test ids to be able to see your ads in testing mode

Related