gpt4 book ai didi

android - Adview 错误!- 不兼容的类型 : View cannot be converted to Adview

转载 作者:行者123 更新时间:2023-11-29 16:41:59 24 4
gpt4 key购买 nike

我正在尝试将 Google Admob 合并到我的 android 应用程序中。我已按照 https://developers.google.com/admob/android/quick-start?hl=en-US#import_the_mobile_ads_sdk 中的指南添加了代码和 https://developers.google.com/admob/android/banner?hl=en-US .但是,我收到错误消息“不兼容的类型:View cannot be converted to Adview”。

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;



public class RecognizeActiv extends AppCompatActivity {

public AdView mAdView;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.recognizeactiv_layout);



MobileAds.initialize(this,
"ca-app-pub-1538792633238746~7576594574");

mAdView = findViewById(R.id.adView); //getting error here.....
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);



}

xml代码

 <com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
xmlns:android="http://schemas.android.com/apk/res/android"

android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
</com.google.android.gms.ads.AdView>

最佳答案

通过 AdView 本身的类型转换来初始化 AdView 对象。

mAdView = (AdView)findViewById(R.id.adView);

关于android - Adview 错误!- 不兼容的类型 : View cannot be converted to Adview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50254383/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com