MobileAds.initialize error: incompatible types: String cannot be converted to OnInitializationCompleteListener

使用 android Studio 2020.1,奇怪的是,在較早更新我的庫後,我在編譯應用程序時遇到此錯誤 incompatible types: String cannot be converted to OnInitializationCompleteListener

我的程式碼:

MobileAds.initialize(this, getString(R.string.admob_banner_id));
mAdView = findViewById(R.id.adView);     //The line that returns the error to me
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);

Google 網路上建議的解法:

Apparently google has changed the way of integrating ads into apps. I went to the site and applied the new rules to my code and everything was back to normal.

For those who will encounter the same problem simply replace your code with this one

AdView adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId(getString(R.string.admob_banner_id));

詳細用法,直接參考Admob 官方的 sample code , 就不會有問題:
https://developers.google.com/admob/android/banner


資料來源:

incompatible types: String cannot be converted to OnInitializationCompleteListener
https://stackoverflow.com/questions/67989141/incompatible-types-string-cannot-be-converted-to-oninitializationcompletelisten

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *