![](/img/trans.png)
[英]ADMOB XML The following classes could not be instantiated: - com.google.android.gms.ads.AdView
[英]adMob XML:The following classes could not be instantiated: - com.google.android.gms.ads.AdView
幾天前我開發了一個Android應用程序..我想在該應用程序中放置廣告但在此之前我想在另一個簡單的應用程序上測試廣告...我按照每個程序一步一步地捆綁lib和一切bla bla但問題是布局,即使在簡單的廣告視圖應用程序中,問題是布局說“以下類無法實例化: - com.google.android.gms.ads.AdView”
有一件事這是我在stackoverflow上的第一篇文章...我一直在與這個錯誤斗爭3天但我找不到解決方案所以我來到這里
這是我的XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.adtest.MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<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="INSERT_YOUR_AD_UNIT_ID_HERE" />
</RelativeLayout>
這是我的清單
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.adtest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<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"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</manifest>
谷歌播放元數據元素:
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
應放在xml中的<application>
中,而不是放在xml中。
另請參閱Google Play服務設置指南 。
如果您在IDE中收到此消息,則表示您的IDE未正確將GooglePlayServices庫加載到其布局編輯器中。 修復此問題是特定於IDE的。
但好消息是,這只會影響IDE中布局的渲染視圖。 它不會在運行時影響您的應用程序。 您可以隨時使用XML編輯器編輯您的布局,恕我直言將為您提供最佳的布局理解。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.