2

我在嘗試加載谷歌AdMob中的InterstitialAd時出現此錯誤。我知道我已經正確編寫了代碼。當我按照https://developers.google.com/mobile-ads-sdk/docs/admob/advanced#play的簡短教程未找到Google Play服務資源。 'AdsMob'

所有發生的是我得到和錯誤在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. 
+0

您是否已將您的id值添加到字符串中? – noobProgrammer

+0

是的。我剛剛替換了這個問題。 –

+0

你可以@Override方法onCreate? – noobProgrammer

回答

1

我有我的運行設備上我的應用程序相同的錯誤。看來這個問題與你的設備有關。嘗試使用你的應用到其他設備

如果廣告將出現,你的代碼似乎沒有問題。

你也可以改變這一行這樣的:

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

確保你在你的項目中正確谷歌播放庫

enter image description here

如果你做了這些: https://developers.google.com/mobile-ads-sdk/docs/ 您的應用廣告應該完美運行

+0

我剛剛嘗試過谷歌示例,它在我的設備上運行良好。 –

+0

看到我的編輯! – noobProgrammer

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. 

是一個良性錯誤。如果廣告顯示,請不要擔心。 你的代碼看起來不錯。

相關問題