必须在调用加载前设置广告尺寸和广告单元ID

时间:2015-04-02 09:34:50

标签: android android-layout

Q1我无法找到解决方案。logCat窗口显示IllegalStateException - "the ad size and ad unit id must be set before load is called " error! " 我使用了res-auto和ad:Size = "BANNER"

<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);
}

如果任何人能回答

将会很有帮助

3 个答案:

答案 0 :(得分: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函数中你关闭'}'的位置?

答案 1 :(得分: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>

答案 2 :(得分:0)

对不起家伙,但问题非常简单!

横幅ID未正确写入

对我来说,坏消息是我遇到了另一个问题! 如果你们中的任何人都能看一眼我真的很感激!

Interstitial Add is not getting loaded in android

再次抱歉这个麻烦! :d