android - android中底部工作表对话框中的AdMob(移动广告)错误
问题描述
任何人都可以帮助我,我制作了一个应用程序,我在应用程序中使用了一个底页对话框,现在我需要将 ADMob 添加到其中一行中,我做了 xml 部分,但是在与底页相关的活动页面中我仍然有一个错误。
这是带有 AdMob 部分的底部工作表的 Java 代码....请告知
private BottomSheetListener mListener;
private TextView aboutSheet;
private ImageView DuctLiteImage, DuctFullImage, ourAppArrow;
private CardView aboutUsCard, storeGoogleCard, ductLiteCard, ductFullCard, recommendedCard, contactUsCard, ourApps;
private TextView ductSizerLite, ductSizerFull, storeGoogle, recommendedStore, contactUs;
LinearLayout ductLiteLayout, ductFullLayout;
AdView mAdView;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.bottom_sheet_layout, container, false);
CardView aboutUsCard = v.findViewById(R.id.about_us_card);
CardView storeGoogleCard = v.findViewById(R.id.store_card);
CardView ductLiteCard=v.findViewById(R.id.duct_lite_card);
CardView ductFullCard=v.findViewById(R.id.duct_full_card);
CardView recommendedCard=v.findViewById(R.id.recommended_card);
CardView contactUsCard=v.findViewById(R.id.conract_us_card);
CardView ourApps=v.findViewById(R.id.our_apps_card);
LinearLayout ductLiteLayout = v.findViewById(R.id.lite_Linear);
LinearLayout ductFullLayout = v.findViewById(R.id.full_layout);
ImageView ourAppArrow = v.findViewById(R.id.ourapp_arrow);
MobileAds.initialize(this, new OnInitializationCompleteListener() {
@Override
public void onInitializationComplete(InitializationStatus initializationStatus) {
}
});
mAdView = v.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
解决方案
在您的代码中使用getActivity()
而不是从您的父活动中传递一个。this
Context
推荐阅读
- python - 如何按 Pandas 中的 2 个多索引列对 sort_values() 进行排序
- python-3.x - Stereo SGBM 与 WLS 视差图中的视差值差异
- r - 向 pheatmap 添加信息
- python - 查询以使用上一个日期的值填充缺失的日期
- php - 为什么未定义的正确 $identifier 显示在错误日志中但未显示在 UI 中
- docker - 无法删除 Kubernetes 中的所有 pod - 清除/重新启动 Kubernetes
- node.js - npm 安装错误版本的 anuglar(8.1.0)
- react-native - 如何将 ActivityIndicator 中心放置到视图中
- r - 将函数应用于列表中所有有意义的组合并以矩阵格式保存
- javascript - 如何使用 nouislider 中的滑块过滤 Leaflet.js 上的聚集标记