Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

StartApp Ad not showing on my App

Tags:

java

android

For some reason,StartApp ads are not showing on my application, despite having followed their setup instructions in the pdf they provided on their site.

I implemented callbacks on the showAd() and loadAd() methods and noted that ads are received but not shown. I later created a rectangular background on the view where start app Ad would be shown.I noticed the view with my rectangular border is shown when the ad is loaded but their is no ad content inside the view. See attached image.

In the log cat, 'Ad received' is reported but never ' Ad displayed' or 'Ad hidden' messages from my callbacks.

When I click on the Ad view, my app crashed with Array Index out of bounds exception thrown from the StartApp lib.

See images and code snippets.

My Show add runnable:

    private Runnable showAdRunnable = new Runnable() {

    @Override
    public void run() {
          /* 
               WAS HERE BUT STILL COULDNT SHOW
               startAppAd.showAd(new AdDisplayListener() {
                @Override
                public void adHidden(Ad ad) {
                    Log.d(TAG, "Ad hidden "+ad.getErrorMessage());
                }
                @Override
                public void adDisplayed(Ad ad) {
                    Log.d(TAG, "Ad displayed "+ad.getErrorMessage());
                }
                }); 
                */
        startAppAd.loadAd (new AdEventListener() {
            @Override
            public void onReceiveAd(Ad ad) {
                Log.d(TAG, "Ad received "+ad.getErrorMessage());

                startAppAd.showAd(new AdDisplayListener() {
                    @Override
                    public void adHidden(Ad ad) {
                        Log.d(TAG, "Ad hidden "+ad.getErrorMessage());
                    }
                    @Override
                    public void adDisplayed(Ad ad) {
                        Log.d(TAG, "Ad displayed "+ad.getErrorMessage());
                    }
                    }); 
            }
            @Override
            public void onFailedToReceiveAd(Ad ad) {
                Log.d(TAG, "Ad not received "+ad.getErrorMessage());
            }
            });
        try {
            Thread.sleep(200);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        showing = false;
    }

};

My onCreate()

/**
 * Called when the activity is first created.
 */
@Override
public void onCreate(final Bundle savedInstanceState) {
    Log.d(TAG, "onCreate()");
    StartAppAd.init(this, "XXXXXXX", "YYYYYYY");
    super.onCreate(savedInstanceState);

           setContentView(R.layout.main);

    // initialize the coin image and result text views
    initViews();

    // initialize the onclick listener
    coinImage.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            tossCoin();
        }
    });

    initSounds();

    showing = true;
    new Handler().postDelayed(showAdRunnable , 2*1000);
}

tossmyCoin() method. This is called when the user clicks on the coin image on my app to toss the coin. I want to refresh the Ad every time the user tosses a coin, so I did:

private void tossCoin() {
    ....

    if (!showing) {
        showing = true;
        new Handler().postDelayed(showAdRunnable , 2*1000);
    }
}

How Ad is shown: Empty Ad section

When I click on the Ad section, my app crashes and the log cat contains the following:

10-21 01:38:47.851: E/AndroidRuntime(23900): FATAL EXCEPTION: main
10-21 01:38:47.851: E/AndroidRuntime(23900): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
10-21 01:38:47.851: E/AndroidRuntime(23900):    at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:257)
10-21 01:38:47.851: E/AndroidRuntime(23900):    at java.util.ArrayList.get(ArrayList.java:311)
10-21 01:38:47.851: E/AndroidRuntime(23900):    at com.startapp.android.publish.banner.banner3d.Banner3D.onTouchEvent(Unknown Source)
10-21 01:38:47.851: E/AndroidRuntime(23900):    at android.view.View.dispatchTouchEvent(View.java:3885)
10-21 01:38:47.851: E/AndroidRuntime(23900):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:903)
like image 857
nmvictor Avatar asked Dec 09 '25 23:12

nmvictor


2 Answers

I don't know why they provide such an incorrect documentation. Every documentation I referred says the same method to show Interstitial ads like this:

startAppAd.showAd();
startAppAd.loadAd();

The order of method calls itself is wrong here. Here's the bit that worked for me:

  • First you loadAd() with its AdEventListener.
  • On its onReceiveAd() method, call the showAd() method.

So it will be something like this:

startAppAd.loadAd(new AdEventListener() {
    @Override
    public void onReceiveAd(Ad ad) {
        System.out.println("Ad received");

        startAppAd.showAd();
    }
}
like image 126
Neerkoli Avatar answered Dec 12 '25 12:12

Neerkoli


I was facing similar issue with StartApp Banner Adds. Adds were not visible despite of all the steps mentioned in their document were completed.

I resolved the issue as follows. Make sure that in banner adds, Height of the add view must be 50dp(android:layout_height="50dp") or more. Adds will not be visible in height less than that.

Hope it helps.

like image 36
matramroid Avatar answered Dec 12 '25 14:12

matramroid



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!