我的应用程序崩溃了。有时,但它确实很少见,我不知道为什么。
在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();
}
}
});
}
}
答案 0 :(得分:0)
我自己找到了答案!
我尝试使用其他版本,每次都有效