Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/217.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 未找到Google Play服务资源';AdsMob&x27;_Android_Admob_Google Play Services_Preferenceactivity_Interstitial - Fatal编程技术网

Android 未找到Google Play服务资源';AdsMob&x27;

Android 未找到Google Play服务资源';AdsMob&x27;,android,admob,google-play-services,preferenceactivity,interstitial,Android,Admob,Google Play Services,Preferenceactivity,Interstitial,当我试图从google AdMob加载并插入Alad时,我遇到了这个错误。我知道我已经正确地编写了代码。当我遵循关于 所有发生的事情就是我在日志中得到了错误。我可能做错了什么 代码如下: public class Pref extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener { /** The view to show the ad. */

当我试图从google AdMob加载并插入Alad时,我遇到了这个错误。我知道我已经正确地编写了代码。当我遵循关于

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

代码如下:

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.

在我的设备上运行我的应用程序时出现相同的错误。问题似乎与您的设备有关。请尝试将您的应用程序用于其他设备

如果广告会出现,你的代码看起来很好

您还可以将此行更改为:

AdRequest adRequest = new AdRequest.Builder().build();
确保项目中有正确的google play库

如果您已完成以下操作: 你的应用程序广告应该工作得很好

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.
这是一个善意的错误。如果广告正在播放,不要担心。
您的代码看起来不错。

是否已将id值添加到字符串中?是。我只是为了这个问题替换了它。你能@Override方法onCreate吗?这不是必需的。活动在没有AdMob代码的情况下运行正常。问题在于AdMob。您的手机是否安装了google play服务?我刚刚尝试了google示例,它在我的设备上运行良好。