使用interstitual.setAdListener的Java NullPointerException(新的AdListener(){(Admob)

时间:2014-05-17 10:01:18

标签: java android admob

代码:

interstitial.setAdListener(new AdListener(){
    public void onAdLoaded(){
        display();
    });
}   

我正在使用AdMob插页式广告,但不知何故,当该线路运行时,有java.lang.NullPointerException。该方法是一种计时器方法,如下所示:

    public void progress(){

        timer = new Timer();
        timer.scheduleAtFixedRate(new TimerTask(){
            public void run(){
                runOnUiThread(new Runnable() {
                    public void run(){
                        progress -= 1;
                        totalTime += 500 - (level - 1) * 50;
                        timeForLevel += 500 - (level - 1) * 50;
                        showTimeForLevel();
                        showTotalTime();
                        if(progress < 0){
                            timer.cancel();
                            interstitial.setAdListener(new AdListener(){
                                public void onAdLoaded(){
                                    display();
                                }
                            });
                        Intent loseIntent = new Intent(Game.this, Lose.class);
                        loseIntent.putExtra("level", level);
                        loseIntent.putExtra("score", score);
                        loseIntent.putExtra("time", totalTime);
                        loseIntent.putExtra("taps", totalTaps);
                        startActivityForResult(loseIntent, 0);
                        }
                        if(progress >= 0){
                            setGraphics();
                        }                       
                        po.getProgress(progress, scrWidth);
                        progressGraphics();                 
                    }           
                });
            }
        }, (long)(500 / Math.pow(1 + 0.2/1, level)), (long)(500 / Math.pow(1 + 0.2/1, level)));

    }

导致此异常的原因是什么?我怎么解决呢?

LogCat错误:

05-17 17:43:51.571: E/AndroidRuntime(6588): FATAL EXCEPTION: main
05-17 17:43:51.571: E/AndroidRuntime(6588): java.lang.NullPointerException
05-17 17:43:51.571: E/AndroidRuntime(6588):     at com.spamclicker.Game$2$1.run(Game.java:158)
05-17 17:43:51.571: E/AndroidRuntime(6588):     at android.os.Handler.handleCallback(Handler.java:730)
05-17 17:43:51.571: E/AndroidRuntime(6588):     at android.os.Handler.dispatchMessage(Handler.java:92)
05-17 17:43:51.571: E/AndroidRuntime(6588):     at android.os.Looper.loop(Looper.java:137)
05-17 17:43:51.571: E/AndroidRuntime(6588):     at android.app.ActivityThread.main(ActivityThread.java:5493)
05-17 17:43:51.571: E/AndroidRuntime(6588):     at java.lang.reflect.Method.invokeNative(Native Method)
05-17 17:43:51.571: E/AndroidRuntime(6588):     at java.lang.reflect.Method.invoke(Method.java:525)
05-17 17:43:51.571: E/AndroidRuntime(6588):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1209)
05-17 17:43:51.571: E/AndroidRuntime(6588):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1025)
05-17 17:43:51.571: E/AndroidRuntime(6588):     at dalvik.system.NativeStart.main(Native Method)

0 个答案:

没有答案