Error inflating class com.google.android.gms.ads.AdView Android Studio(膨胀类 com.google.android.gms.ads.AdView Android Studio 时出错)
问题描述
我要疯了.
我正在尝试使用 google play 服务更改 admob.但我被这个错误困住了.
I'm trying to change admob using google play services. But i'm stuck on this error.
Caused by: android.view.InflateException: Binary XML file line #53: Error inflating class com.google.android.gms.ads.AdView
我有这个:
<com.google.android.gms.ads.AdView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:id="@+id/adViewPers"/>
还有这个:
<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" />
主要活动
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
...
private AdView adViewPers;
...
adViewPers = (AdView) findViewById(R.id.adViewPers);
adViewPers.setAdUnitId("xxxxxxx");
adViewPers.setAdSize(AdSize.SMART_BANNER);
AdRequest adRequest = new AdRequest.Builder().build();
adViewPers.loadAd(adRequest);
并在依赖项中:
我做错了什么????
推荐答案
包含 Google Play 服务的更好方法是通过项目结构"对话框中的库依赖项——而不是像您所做的那样添加 jar 文件,单击+ 按钮 > 库依赖项.Google Play 服务应该在列表中.
The better way to include Google Play Services is via a Library dependency in the Project Structure dialog -- instead of adding the jar file as you have done, click the + button > Library dependency. Google Play Services should be in the list.
另外,如果您要添加 jar 文件,最好不要将它们放在 build 文件夹中——如果您进行干净的构建,它可能会被删除.最好的位置是模块根目录下的 libs 目录.
Also, if you're adding jar files, it's really best to not put them in the build folder -- that can get erased if you do a clean build. The best place is in a libs directory at your module root.
这篇关于膨胀类 com.google.android.gms.ads.AdView Android Studio 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:膨胀类 com.google.android.gms.ads.AdView Android Studio 时出错


基础教程推荐
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01