Android 我使用AdMob后,应用程序在启动时不断崩溃

Android 我使用AdMob后,应用程序在启动时不断崩溃,android,admob,Android,Admob,在我尝试使用AdMob的横幅广告而不使用它之后,我的应用程序一直崩溃,一切正常。SplashScreen会加载,但当游戏开始时应用程序会崩溃。以下是我实现这一目标的步骤: 1我确保安装了Google Play服务和Google存储库 2然后我使用Firebase工具助手将我的应用程序连接到Firebase,它只是在我的项目的应用程序文件夹下添加了google services.json 3当我将AdMob添加到我的应用程序时,如下所示: 4我在布局中添加了以下代码: xmlns:ads="htt

在我尝试使用AdMob的横幅广告而不使用它之后,我的应用程序一直崩溃,一切正常。SplashScreen会加载,但当游戏开始时应用程序会崩溃。以下是我实现这一目标的步骤:

1我确保安装了Google Play服务和Google存储库

2然后我使用Firebase工具助手将我的应用程序连接到Firebase,它只是在我的项目的应用程序文件夹下添加了google services.json

3当我将AdMob添加到我的应用程序时,如下所示:

4我在布局中添加了以下代码:

xmlns:ads="http://schemas.android.com/apk/res-auto"

 <com.google.android.gms.ads.AdView
    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="@string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
6将此添加到我的字符串中:ca-app-pub-3940256099942544/630978111

7在我的AndroidManifest.xml中,我添加了以下代码:

<!-- Include required permissions for Google Mobile Ads to run-->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

<!--This meta-data tag is required to use Google Play services.-->
    <meta-data android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version" />

<!--Include the AdActivity configChanges and theme. -->
    <activity android:name="com.google.android.gms.ads.AdActivity"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
        android:theme="@android:style/Theme.Translucent" />
如果有人能帮忙的话,我想知道怎么回事

以下是崩溃日志:

findviewbydr.id.adView;如果视图存在于您在setContentView中提供的布局中,则返回该视图,否则返回null,这就是发生在您身上的情况

mAdView为空,因此您将获得空指针异常


因此,创建一个layout.xml,嵌入GamePanel视图和AdView,然后将该布局传递给setContentView;方法。

请记录崩溃日志?您好!我添加了崩溃日志。谢谢你的帮助@MOISONIONUT在游戏面板上显示我的代码,是什么?
<!-- Include required permissions for Google Mobile Ads to run-->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

<!--This meta-data tag is required to use Google Play services.-->
    <meta-data android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version" />

<!--Include the AdActivity configChanges and theme. -->
    <activity android:name="com.google.android.gms.ads.AdActivity"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
        android:theme="@android:style/Theme.Translucent" />