2015-04-02 79 views
0

Q1我不能找到解決辦法之前設置.. logCat窗口顯示IllegalStateException - "the ad size and ad unit id must be set before load is called " error! " 我用資源,汽車和ad:Size = "BANNER"的廣告尺寸和廣告單元ID必須負載被稱爲

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
xmlns:ads="http://schemas.androhttps://stackoverflow.com/posts/29409592/editid.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingLeft="0dp" 
android:label="@string/app_name" 
android:paddingRight="0dp" 
android:paddingTop="0dp" 
android:paddingBottom="0dp" tools:context=".MainActivity"> 
<com.example.jatinarora.threestickhockey.mView 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
/> 
    <com.google.android.gms.ads.AdView 
    android:id="@+id/abcde" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:layout_alignParentTop="true" 
    ads:adSize="BANNER" 
    ads:adUnitId="@string/banner_ad_unit_id2"> 
</com.google.android.gms.ads.AdView> 
</RelativeLayout> 

這是我的MainActivity類別的onCreate功能

public class MainActivity extends ActionBarActivity { 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    WindowManager.LayoutParams.FLAG_FULLSCREEN); 
    setContentView(R.layout.activity_main); 
    AdView mAdView; 
    mAdView = (AdView) findViewById(R.id.abcde); 
    AdRequest adRequest = new AdRequest.Builder() 
    .build(); 
    mAdView.loadAd(adRequest); 
} 

這將是很大的幫助,如果任何人能回答

+0

Legendary 2015-04-02 09:41:09

+0

不使用相對佈局的adview而是使用線性佈局 – WISHY 2015-04-02 10:32:36

回答

0
public class MainActivity extends ActionBarActivity { 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    WindowManager.LayoutParams.FLAG_FULLSCREEN); 
    setContentView(R.layout.activity_main); 
    AdView mAdView; 
    mAdView = (AdView) findViewById(R.id.abcde); 
    AdRequest adRequest = new AdRequest.Builder() 
    .build(); 
    mAdView.loadAd(adRequest); 
} 

你在哪裏關閉'}'onCreate函數?

0

改變你的XML是這樣的

<com.google.android.gms.ads.AdView 
xmlns:ads="http://schemas.android.com/apk/res-auto" 
android:id="@+id/abcde" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
ads:adSize="BANNER" 
ads:adUnitId="@string/banner_ad_unit_id2" 
ads:loadAdOnCreate="true" > 
</com.google.android.gms.ads.AdView> 
0

對不起球員,但問題是很瑣碎!

旗幟ID沒有被正確

書面

對我來說是壞消息是我被困在一個問題! 如果你們中的任何人都能看一看,我會非常感激!

Interstitial Add is not getting loaded in android

和麻煩又對不起! :D