Java ADMOB:无法实例化以下类:-com.google.android.gms.ads.AdView
我将opld admob更新为新的admob。我下载了SDK,导入了google play服务库,并在google documantation中完成了所有工作。但当我添加xml代码时:Java ADMOB:无法实例化以下类:-com.google.android.gms.ads.AdView,java,android,eclipse,sdk,admob,Java,Android,Eclipse,Sdk,Admob,我将opld admob更新为新的admob。我下载了SDK,导入了google play服务库,并在google documantation中完成了所有工作。但当我添加xml代码时: <com.google.android.gms.ads.AdView android:id="@+id/adView" android:layout_width="wrap_content" android:layout_h
<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
编辑:
存在清单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"/>
你能帮我吗?请确保在布局中使用正确的广告名称空间。您应该使用: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"/>
致:
也发布manifest.xml代码。您是在Eclipse中还是在运行时遇到此错误?您使用的是play services库的版本4还是更高版本?Admob在gps 4+中可用。我当前安装的版本是19.No。我指的是google play服务库的版本。打开它的清单文件并签出版本名。您应该会看到类似这样的内容:android:versionName=4.3.23 1069729-030Android:versionName=5.0.89-000 5089000如果您有旧的admob sdk jar和Google Play服务,请从libs文件夹中删除旧的admob sdk并清理您的项目
<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"/>