繁体   English   中英

adMob XML:无法实例化以下类: - 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM