我的问题是在安卓应用程序中添加谷歌广告



java.lang.NullPointerException:尝试调用虚拟方法'voidcom.google.android.gms.ads.AdView.loadAd(com.google.aAndroid.gms.ads.AdRequest('在空对象r 上

public class Activity1 extends Activity {
Button btnrateapp, btnnext,btnshareapp;
int share,rate;
private AdView adView;
private InterstitialAd mInterstitialAd;
int i = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity1);
// MobileAds.initialize(this, "ca-app-pub-3297215203354227~5525786209");
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-app-pub-9817937406815779/5109921994");
mInterstitialAd.loadAd(new AdRequest.Builder().build());
adView =findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
//mAdView.loadAd(new AdRequest.Builder().build());
adView.loadAd(adRequest);

您必须在布局活动1.xml:中添加此代码

<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="ad_unit_id_for_banner_here"/>

相关内容

  • 没有找到相关文章

最新更新