Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

//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
like image 607
kumar bittu Avatar asked Nov 16 '22 00:11

kumar bittu


1 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.

like image 153
carrizo Avatar answered Dec 16 '22 05:12

carrizo