【问题标题】:android: InterstitialAd : StartUp must implement the inherited abstract methodandroid: InterstitialAd : StartUp 必须实现继承的抽象方法
【发布时间】:2012-11-27 15:04:22
【问题描述】:
import com.google.ads.*;
import com.google.ads.AdListener;
import com.google.ads.AdRequest;
import com.google.ads.InterstitialAd;

public class StartUp extends Activity implements AdListener {

    private InterstitialAd interstitialAd;   
    AdView adView;

       public static final  String MY_PUBLISHER_ID = "abc"; 

       @Override
       public void onCreate(Bundle savedInstanceState) 
       {
          super.onCreate(savedInstanceState); // call the superclass's method
          setContentView(R.layout.main_first_page); // inflate the GUI

          interstitialAd = new InterstitialAd(this, MY_PUBLISHER_ID); // Create an ad.  
          interstitialAd.setAdListener(this); // Set the AdListener.
          AdRequest adRequest = new AdRequest();
          adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
          interstitialAd.loadAd(adRequest);       
          if (interstitialAd.isReady()) {interstitialAd.show();}

          Button ButtonIQ= (Button) findViewById(R.id.buttonA);    

       }

错误:

公有类StartUp报错,Eclipse报“类型StartUp必须实现继承的抽象方法AdListener.onPresentScreen(Ad)”。

请问这是什么问题,如何解决?非常感谢!

【问题讨论】:

    标签: android layout interstitial


    【解决方案1】:

    抽象类不能被实例化。您必须创建一个实现抽象类的“具体”或真实类,您已经完成了。

    抽象类也可以定义具体类必须提供的抽象方法。在这种情况下,您没有为 onPresentScreen() 提供方法,因此您会看到错误。

    http://docs.oracle.com/javase/tutorial/java/IandI/abstract.html

    请参阅 AdListener 文档,了解如何实现此方法,该方法在广告全屏显示时调用。

     @Override
        public void onPresentScreen() {
             // called when a full screen ad is presented
        }
    

    【讨论】:

    • 感谢您的帮助!我已经添加了那些 OnPresentScreen、onLeaveApplication 等,然后就没有更多错误了!但是,当我尝试运行应用程序时,没有显示此类广告弹出窗口。为什么? (可以正常执行onReceiveAd)
    • 请将此标记为答案,因为它解决了问题,然后用新问题开始另一个问题。请记得发布相关代码。 StackOverflow 最适合每个帖子一个问题。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2013-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-21
    相关资源
    最近更新 更多