【问题标题】:My app crashes when the Admob ad is displayed (Interstitial Ad)显示 Admob 广告时我的应用程序崩溃(插页式广告)
【发布时间】:2017-12-25 14:00:36
【问题描述】:

我的应用程序在按下按钮“mMyButton”后崩溃。有时,但真的很少见,我不知道为什么。

在xml文件中只有按钮“mMyButton”。

你能帮帮我吗,因为我尝试了很多不同的方法,但都没有成功。

package com.example.rapha.rafisapp.Firebase;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.example.rapha.rafisapp.R;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.InterstitialAd;
import com.google.android.gms.ads.MobileAds;

public class Admob_Interstitial extends AppCompatActivity {

private InterstitialAd mInterstitialAd;
private static final String TAG = "lollogtag";
private Toast toast = null;

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

    toast = Toast.makeText(getApplicationContext(), "", Toast.LENGTH_SHORT);

    Button mMyButton = (Button) findViewById(R.id.button);


    MobileAds.initialize(this, "ca-app-pub-9955387151447653~2362893982");

    mInterstitialAd = new InterstitialAd(this);
    mInterstitialAd.setAdUnitId("ca-app-pub-9955387151447653/8105410912");
    mInterstitialAd.loadAd(new AdRequest.Builder().build());


    mMyButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mInterstitialAd.isLoaded()) {
                mInterstitialAd.show();
                Log.d(TAG, "ad loaded and shown");
                toast.setText("Loaded");
                toast.show();
            } else {
                Log.d(TAG, "The interstitial wasn't loaded yet.");
                toast.setText("The Ad wasn't loaded yet");
                toast.show();
            }
        }
    });

}
}

【问题讨论】:

  • 捕获日志并在您的问题中更新

标签: android admob interstitial


【解决方案1】:

我自己找到了答案!

我尝试使用不同的版本,但每次都有效

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-25
    • 1970-01-01
    • 2014-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多