2

当我尝试从 google AdMob 加载和 InterstitialAd 时出现此错误。我知道我已经正确地编写了代码。当我按照https://developers.google.com/mobile-ads-sdk/docs/admob/advanced#play上的简短教程进行操作时

所有发生的事情都是我在 Logcat 中得到错误。我可能做错了什么。

这是代码:

public class Pref extends PreferenceActivity implements
        SharedPreferences.OnSharedPreferenceChangeListener {

    /** The view to show the ad. */
      private AdView adView;

      /* Your ad unit id. Replace with your actual ad unit id. */
      private static final String AD_UNIT_ID = "MY_ID";
      private static final String inAD_UNIT_ID = "MY_ID";
      private InterstitialAd interstitial;


    @SuppressWarnings("deprecation")
    protected void onCreate(Bundle paramBundle) {
        super.onCreate(paramBundle);
        setContentView(R.layout.ad_layout);


        //addPreferencesFromResource(R.xml.preferences);
        //getPreferenceManager()
                //.setSharedPreferencesName("com.gordondev.south_korea");
        //addPreferencesFromResource(2130903040);
        //getPreferenceManager().getSharedPreferences()
            //  .registerOnSharedPreferenceChangeListener(this);

        // Create the interstitial.
        interstitial = new InterstitialAd(this);
        interstitial.setAdUnitId(inAD_UNIT_ID);

        // Create ad request.
        AdRequest adRequest = new AdRequest.Builder().build();

        // Begin loading your interstitial.
        interstitial.loadAd(adRequest);

        // Create an ad.
        adView = new AdView(this);
        adView.setAdSize(AdSize.BANNER);
        adView.setAdUnitId(AD_UNIT_ID);

        // Add the AdView to the view hierarchy. The view will have no size
        // until the ad is loaded.
        LinearLayout layout = (LinearLayout) findViewById(R.id.adview);
        layout.addView(adView);

        //((LinearLayout)view).addView(adView);

        // Create an ad request. Check logcat output for the hashed device ID to
        // get test ads on a physical device.
        AdRequest adRequest1 = new AdRequest.Builder()
            .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            .addTestDevice("INSERT_YOUR_HASHED_DEVICE_ID_HERE")
            .build();

        // Start loading the ad in the background.
        adView.loadAd(adRequest1);


    }

    // Invoke displayInterstitial() when you are ready to display an interstitial.
      public void displayInterstitial() {
        if (interstitial.isLoaded()) {
          interstitial.show();
        }
      }

这是 Logcat 错误:

03-13 16:49:41.565: I/Ads(29755): Use AdRequest.Builder.addTestDevice("099098AA8954CC0C01AD412143D81BDD") to get test ads on this device.
03-13 16:49:41.565: I/Ads(29755): Starting ad request.
03-13 16:49:41.575: E/GooglePlayServicesUtil(29755): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
03-13 16:49:41.575: I/Ads(29755): Use AdRequest.Builder.addTestDevice("099098AA8954CC0C01AD412143D81BDD") to get test ads on this device.
03-13 16:49:41.575: I/Ads(29755): Starting ad request.
03-13 16:49:41.585: E/GooglePlayServicesUtil(29755): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
03-13 16:49:41.625: E/GooglePlayServicesUtil(29755): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
03-13 16:49:41.635: E/GooglePlayServicesUtil(29755): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
03-13 16:49:41.645: E/GooglePlayServicesUtil(29755): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
03-13 16:49:41.645: E/GooglePlayServicesUtil(29755): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
03-13 16:49:42.365: I/Ads(29755): Ad finished loading.
03-13 16:49:43.085: I/Ads(29755): Scheduling ad refresh 60000 milliseconds from now.
03-13 16:49:43.085: I/Ads(29755): Ad finished loading.
4

2 回答 2

1
03-13 16:49:41.585: E/GooglePlayServicesUtil(29755): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.

是良性错误。如果广告正在展示,请不要担心。你的代码看起来不错。

于 2014-03-14T04:07:38.013 回答
1

我在我的设备上运行我的应用程序时遇到同样的错误。似乎问题与您的设备有关。尝试将您的应用程序用于另一台设备

如果广告会出现,您的代码似乎没问题。

您也可以将此行更改为:

AdRequest adRequest = new AdRequest.Builder().build();

确保您的项目中有正确的google play 库

在此处输入图像描述

如果您已完成以下操作:https ://developers.google.com/mobile-ads-sdk/docs/ 您的应用广告应该可以完美运行

于 2014-03-13T21:28:22.360 回答