【问题标题】:ADMOB: The following classes could not be instantiated: - com.google.android.gms.ads.AdViewADMOB:无法实例化以下类:- com.google.android.gms.ads.AdView
【发布时间】:2014-08-20 17:05:08
【问题描述】:

我将我的 opld admob 更新为新的 admob。我下载了 SDK,导入了 google play 服务库并在 google 文档中完成了所有操作。但是当我添加xml代码时:

<com.google.android.gms.ads.AdView android:id="@+id/adView"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     ads:adUnitId="ca-app-pub-111111111111111/1111111"
                     ads:adSize="BANNER"/>

我在错误日志中收到以下消息:

无法实例化以下类: - com.google.android.gms.ads.AdView

编辑: 有 Manifest XML 代码:

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

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

<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>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

你能帮帮我吗?

【问题讨论】:

  • 也发布 manifest.xml 代码。
  • 您是在 Eclipse 中还是在运行时收到此错误?

标签: java android eclipse sdk admob


【解决方案1】:

确保在布局中使用正确的广告命名空间。你应该使用:xmlns:ads="http://schemas.android.com/apk/res-auto"

所以改变:

 <com.google.ads.AdView
        xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
        android:id="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        ads:adUnitId="MY_AD_UNIT_ID"
        ads:adSize="BANNER"
        ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
        ads:loadAdOnCreate="true"/>

收件人:

<com.google.android.gms.ads.AdView
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:id="@+id/adView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    ads:adUnitId="MY_AD_UNIT_ID"
    ads:adSize="BANNER"/>

【讨论】:

  • 您使用的是第 4 版或更高版本的播放服务库吗? Admob 在 gps 4+ 中可用
  • 我目前安装的版本是 19。
  • 没有。我的意思是谷歌播放服务库的版本。打开它的清单文件并检查版本名称。你应该会看到类似:android:versionName="4.3.23 (1069729-030)"
  • Android:versionName="5.0.89-000 (5089000)
  • 如果您有旧的 admob sdk jar 以及 Google Play 服务,则从您的 libs 文件夹中删除旧的 admob sdk 并清理您的项目
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-30
相关资源
最近更新 更多