gpt4 book ai didi

Android - 新的 AdmobApi 不适用于 android 中的广告

转载 作者:行者123 更新时间:2023-11-30 02:41:04 25 4
gpt4 key购买 nike

我正在开发最新的 android SDK 23 并尝试在我的应用中添加 admob 广告。所以我关注了 admob guied line video guied 这也是,但我仍然遇到错误

错误

FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.adtest/com.android.adtest.MainActivity}: android.view.InflateException: Binary XML file line #10: Error inflating class com.google.android.gms.ads.AdView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2343)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395)
at android.app.ActivityThread.access$600(ActivityThread.java:162)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
at android.os.Handler.dispatchMessage(Handler.java:107)
Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class com.google.android.gms.ads.AdView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:698)
at android.app.Activity.performCreate(Activity.java:5122)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307)
... 11 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.ads.AdView" on path: DexPathList[[zip file "/data/app/com.android.adtest-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.android.adtest-1, /vendor/lib, /system/lib]]
at android.view.LayoutInflater.createView(LayoutInflater.java:552)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
... 24 more

我不知道哪里出错了。请帮帮我。提前致谢。

我什至可以在图形布局中看到 adView。它在 android 中显示灰色布局。

主.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="AAA"/>
<com.google.android.gms.ads.AdView android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="MY ID"/>
</LinearLayout>

我可以在我的 .java 文件中找到 com.google.android.gms.ads.AdView 但无法在 .xml 文件中找到

list .xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.adtest"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
</application>

</manifest>

enter image description here

最佳答案

关注这个link

您将需要向您的 onCreate() 添加一些 java 代码,同时尝试按照右栏中的步骤一一进行操作

// Java code required.
// testDevices and loadAdOnCreate attributes are
// no longer available.
AdView adView = (AdView)this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("TEST_DEVICE_ID")
.build();
adView.loadAd(adRequest);

关于Android - 新的 AdmobApi 不适用于 android 中的广告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25743163/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com