添加admob后,Android应用无法启动

时间:2017-08-07 12:00:37

标签: android admob

我正在开发一个Android应用程序,我在其中使用admob来展示广告但是在我从admob放置横幅广告之后它无法启动。 这是我的xml代码,

cellRenderer ({ columnIndex, key, rowIndex, style }) {
  const {
    myWideDataTable
  } = this.state

  return (
    <div
      {myWideDataTable}
    </div>)
}

// in render()

<Grid
  cellRenderer={this.cellRenderer}
  columnCount={1}
  columnWidth={1000}
  height={1000}
  rowCount={1}
  rowHeight={30}
  width={1000}
/>

我已将其添加到清单文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical">

<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:auto="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_above="@+id/adView"
android:background="@color/bg"
android:scrollbars="vertical"
app:ignore="NamespaceTypo">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_marginStart="@dimen/lml"
    android:layout_marginEnd="@dimen/lmr"
    android:layout_marginTop="@dimen/lmt"
    android:layout_marginBottom="@dimen/lmb"
    android:background="@color/bg"
    >

    <TextView
        android:id="@+id/lpp1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="@dimen/content"
        android:textColor="@color/content"
        android:lineSpacingMultiplier="1.2"
        android:background="@color/bg"
        android:text="@string/lpp1"
        />

</LinearLayout>
</ScrollView>

<com.google.android.gms.ads.AdView
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_alignParentBottom="true"
    ads:adSize="BANNER"
    ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
</com.google.android.gms.ads.AdView>
</RelativeLayout>

我已经在stackoverflow上阅读了很多与此相关的问题并搜索了这个问题并尝试了一些但仍然无法解决问题。任何人都可以指出问题所在。

Java文件详细信息

<meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
    <activity android:name="com.google.android.gms.ads.AdActivity"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>

logcat的

  MobileAds.initialize(this, "xxxxxxxxxx");

    AdView mAdView = (AdView) findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);

1 个答案:

答案 0 :(得分:0)

我建议您检查一下您是否已将AdView添加到活动布局中。 像这样:

layout = findViewById(R.id.root_layout);
layout.addView(mAdView);

然后,您可以使用AdView加载广告:

mAdView.loadAds(adRequest);