必须在添加内容之前调用requestFeature()(AdMob)

时间:2016-06-27 07:51:32

标签: android admob

我收到了这个错误,我不知道是什么原因引起的。 你能帮我解决这个错误吗? 我该如何解决这个问题?

*     java.lang.RuntimeException:无法启动活动ComponentInfo {com.sample.app/com.google.android.gms.ads.AdActivity}:android.util.AndroidRuntimeException:在添加内容之前必须调用requestFeature()     在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2658)     在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2723)     在android.app.ActivityThread.access $ 900(ActivityThread.java:172)     在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1422)     在android.os.Handler.dispatchMessage(Handler.java:102)     在android.os.Looper.loop(Looper.java:145)     在android.app.ActivityThread.main(ActivityThread.java:5832)     at java.lang.reflect.Method.invoke(Native Method)     在java.lang.reflect.Method.invoke(Method.java:372)     在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1399)     在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)     引起:android.util.AndroidRuntimeException:在添加内容之前必须调用requestFeature()     在com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:352)     在android.app.Activity.requestWindowFeature(Activity.java:3759)     在com.google.android.gms.ads.internal.overlay.ab.a(:com.google.android.gms.DynamiteModulesA:279)     在com.google.android.gms.ads.internal.overlay.client.c.onTransact(:com.google.android.gms.DynamiteModulesA:58)     在android.os.Binder.transact(Binder.java:380)     在com.google.android.gms.internal.zzfk $ zza $ zza.onCreate(未知来源)     在com.google.android.gms.ads.AdActivity.onCreate(未知来源)     在android.app.Activity.performCreate(Activity.java:6221)     在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)     在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2611)     在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2723)     在android.app.ActivityThread.access $ 900(ActivityThread.java:172)     在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1422)     在android.os.Handler.dispatchMessage(Handler.java:102)     在android.os.Looper.loop(Looper.java:145)     在android.app.ActivityThread.main(ActivityThread.java:5832)     at java.lang.reflect.Method.invoke(Native Method)     在java.lang.reflect.Method.invoke(Method.java:372)     在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1399)     在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)*

这是我的xml代码

  <com.google.android.gms.ads.AdView
    android:id="@+id/ad_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_alignParentBottom="true"
    ads:adSize="BANNER"
    ads:adUnitId="@string/banner_ad_unit_id" />

在我的自定义视图的onFinishInflate上声明它

 @Override
protected void onFinishInflate() {
    super.onFinishInflate();
   mAdView = (AdView) findViewById(R.id.ad_view);
   AdRequest adRequest = new AdRequest.Builder()
            .build();
   adView.loadAd(adRequest);
}

0 个答案:

没有答案