Admob onAdLoaded was Called But nothing is shown in screen Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Admob onAdLoaded was Called But nothing is shown in screen without wasting too much if your time.

The question is published on by Tutorial Guruji team.

i was trying to use Admob using sample test id they have given. I’ve added maven repository in project level build.gradle and implemented play services ads in app build.gradle. when i run the app. onAdLoaded method was called. but there is nothing on my screen. i have tried with my own unique ad id too. but the result is same. please help

Main Activity

 package com.twotwotwo.dip.admobtry;

    import android.os.Bundle;
    import android.view.View;
    import android.widget.Toast;


    public class MainActivity extends AppCompatActivity {
        AdView mAdView;

        protected void onCreate(Bundle savedInstanceState) {

            MobileAds.initialize(this, "ca-app-pub-3940256099942544~3347511713");

            mAdView = new AdView(this);

            AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).build();

            mAdView.setAdListener(new AdListener() {
                public void onAdLoaded() {
                    // Code to be executed when an ad finishes loading.
                    showToast("Ad loaded");
                    if (mAdView.getVisibility() == View.GONE) {

                public void onAdFailedToLoad(int errorCode) {
                    // Code to be executed when an ad request fails.
                    if(errorCode == AdRequest.ERROR_CODE_INTERNAL_ERROR){
                        showToast(" Something happened internally");
                    } else if(errorCode == AdRequest.ERROR_CODE_INVALID_REQUEST){
                        showToast("The ad request was invalid; for instance, the ad unit ID was incorrect.");
                    } else if(errorCode == AdRequest.ERROR_CODE_NETWORK_ERROR){
                        showToast("The ad request was unsuccessful due to network connectivity.");
                    } else if(errorCode == AdRequest.ERROR_CODE_NO_FILL){
                        showToast("The ad request was successful, but no ad was returned due to lack of ad inventory.");

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

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

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

        private void showToast(String message){
            Toast.makeText(MainActivity.this, message, Toast.LENGTH_SHORT).show();


you are missing this line

mAdView=(AdView) findViewbyid(
We are here to answer your question about Admob onAdLoaded was Called But nothing is shown in screen - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji