Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
765 views
in Technique[技术] by (71.8m points)

java - StartApp Ad not showing on my App

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)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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();
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...