Admob 广告不会加载.错误2. 之前可以用,突然停止了

Admob ad will not load. Error 2. It worked before but suddenly stopped(Admob 广告不会加载.错误2. 之前可以用,突然停止了)

本文介绍了Admob 广告不会加载.错误2. 之前可以用,突然停止了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我试图将横幅广告加载到的整个类(createAd() 方法完成了工作)

Here is the entire class that I am trying to load a banner ad into (createAd() method does the work)

public class HomeActivity extends Activity {

    private HomeView homeView;
    private ImageView playButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

//        playButton = (ImageView)findViewById(R.id.playButton);
//        playButton.setImageBitmap(BitmapFactory.decodeResource(getResources(),
//                R.drawable.play));
//        setListener();
        setContentView(R.layout.home_main);
        createAd();

    }

    private void setListener (){
        playButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                playButton.setImageBitmap(BitmapFactory.decodeResource(getResources(),
                        R.drawable.play2));
                playGame();
            }
        });
    }

    private void createAd(){
        setContentView(R.layout.home_main);
        AdView adView = (AdView)findViewById(R.id.bottomAd);
        AdRequest.Builder adRequestBuilder = new AdRequest.Builder();
        adRequestBuilder.addTestDevice("FEACCF89D31180ABDD853C9C3DD2E871");
//                .addTestDevice("1744314CD0C7B0619F94D44CE2E5093E");

        adView.loadAd(adRequestBuilder.build());
    }

    public void playGame() {
        SharedPreferences savedData = getApplicationContext()
                .getSharedPreferences("lastScore", Context.MODE_PRIVATE);
        int score = savedData.getInt("lastScore", Context.MODE_PRIVATE);
        Intent intent = new Intent(HomeActivity.this, GamePlay.class);
        intent.putExtra("lastScore", score);
        startActivity(intent);
        finish();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

这里是home_main的xml

Here is the xml of home_main

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/homeRelative"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".HomeActivity">

    <com.google.android.gms.ads.AdView
        xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:id="@+id/bottomAd"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="@string/admob_banner_id">
    </com.google.android.gms.ads.AdView>

</RelativeLayout>

这是我最近一次运行后的日志

Here is my log after the most recent run

 01-01 16:00:32.235  26387-26387/com.rune.colorhunt D/OpenGLRenderer﹕ Enabling debug mode 0
01-01 16:00:32.275      652-796/? I/CrashAnrDetector﹕ onPackageUpdateFinished : com.rune.colorhunt
01-01 16:00:37.351  26387-26416/com.rune.colorhunt D/dalvikvm﹕ DexOpt: --- BEGIN 'ads976472321.jar' (bootstrap=0) ---
01-01 16:00:37.361  26387-26387/com.rune.colorhunt V/WebViewChromium﹕ Binding Chromium to the main looper Looper (main, tid 1) {41d00b38}
01-01 16:00:37.361  26387-26387/com.rune.colorhunt I/chromium﹕ [INFO:library_loader_hooks.cc(112)] Chromium logging enabled: level = 0, default verbosity = 0
01-01 16:00:37.361  26387-26387/com.rune.colorhunt I/BrowserProcessMain﹕ Initializing chromium process, renderers=0
01-01 16:00:37.391  26387-26426/com.rune.colorhunt W/chromium﹕ [WARNING:proxy_service.cc(888)] PAC support disabled because there is no system implementation
01-01 16:00:37.421  26387-26387/com.rune.colorhunt I/Ads﹕ Starting ad request.
01-01 16:00:37.441  26387-26416/com.rune.colorhunt D/dalvikvm﹕ DexOpt: --- END 'ads976472321.jar' (success) ---
01-01 16:00:37.441  26387-26416/com.rune.colorhunt D/dalvikvm﹕ DEX prep '/data/data/com.rune.colorhunt/cache/ads976472321.jar': unzip in 0ms, rewrite 91ms
01-01 16:00:37.611  26387-26394/com.rune.colorhunt I/dalvikvm﹕ Total arena pages for JIT: 11
01-01 16:00:37.611  26387-26394/com.rune.colorhunt I/dalvikvm﹕ Total arena pages for JIT: 12
01-01 16:00:37.621  26387-26394/com.rune.colorhunt I/dalvikvm﹕ Total arena pages for JIT: 13
01-01 16:00:37.621  26387-26394/com.rune.colorhunt I/dalvikvm﹕ Total arena pages for JIT: 14
01-01 16:00:37.651  26387-26431/com.rune.colorhunt W/Ads﹕ There was a problem getting an ad response. ErrorCode: 2
01-01 16:00:37.691  26387-26387/com.rune.colorhunt I/Ads﹕ Scheduling ad refresh 60000 milliseconds from now.
01-01 16:00:37.691  26387-26387/com.rune.colorhunt W/Ads﹕ Failed to load ad: 2
01-01 16:01:37.715  26387-26387/com.rune.colorhunt I/Ads﹕ Starting ad request.
01-01 16:01:37.825  26387-26490/com.rune.colorhunt W/Ads﹕ There was a problem getting an ad response. ErrorCode: 2
01-01 16:01:37.845  26387-26387/com.rune.colorhunt I/Ads﹕ Scheduling ad refresh 60000 milliseconds from now.
01-01 16:01:37.845  26387-26387/com.rune.colorhunt W/Ads﹕ Failed to load ad: 2
01-01 16:02:37.889  26387-26387/com.rune.colorhunt I/Ads﹕ Starting ad request.
01-01 16:02:38.009  26387-26531/com.rune.colorhunt W/Ads﹕ There was a problem getting an ad response. ErrorCode: 2
01-01 16:02:38.039  26387-26387/com.rune.colorhunt I/Ads﹕ Scheduling ad refresh 60000 milliseconds from now.
01-01 16:02:38.039  26387-26387/com.rune.colorhunt W/Ads﹕ Failed to load ad: 2
01-01 16:03:38.972  26387-26387/com.rune.colorhunt I/Ads﹕ Starting ad request.
01-01 16:03:39.062  26387-26783/com.rune.colorhunt W/Ads﹕ There was a problem getting an ad response. ErrorCode: 2
01-01 16:03:39.062  26387-26387/com.rune.colorhunt I/Ads﹕ Scheduling ad refresh 60000 milliseconds from now.
01-01 16:03:39.062  26387-26387/com.rune.colorhunt W/Ads﹕ Failed to load ad: 2

如果有人能帮助我,那就太棒了.我真的不知道问题可能是什么.也许我错过了一些非常简单的东西,只需要另一双眼睛.任何帮助表示赞赏,谢谢.

If somebody would help me, that would be amazing. I literally have no idea what the problem could be. Perhaps im missing something very simple and just need another pair of eyes. Any help is appreciated, thanks.

推荐答案

检查您的设备是否有正确的互联网连接.如果没有互联网连接,您将不会看到广告.

Check that your device has a proper internet connection. Without internet connection you will not get ads.

这篇关于Admob 广告不会加载.错误2. 之前可以用,突然停止了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Admob 广告不会加载.错误2. 之前可以用,突然停止了

基础教程推荐