Adnan Khalid
Adnan Khalid

Reputation: 11

adMob XML:The following classes could not be instantiated: - com.google.android.gms.ads.AdView

few days ago i developed an android app..i wanted to put ads in that app but before i do that i wanted to test Ads on another simple app...i followed every single procedure step by step bundling the lib and everything bla bla but the problem is in layout even in a simple ad view app the problem is that layout says"The following classes could not be instantiated: - com.google.android.gms.ads.AdView"

and one thing this is my first post on stackoverflow...i have been fighting with this error for 3 days but i could not find the solution so i came here

This is my XML here

<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>

this is my Manifest

<?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>

Upvotes: 1

Views: 387

Answers (2)

William
William

Reputation: 20196

If you are getting this message in your IDE then it means that your IDE is not correctly loading the GooglePlayServices library into its layout editor. Fixing this is IDE specific.

But the good news is that this only affects a rendered view of your layout in your IDE. It doesn't affect your app at runtime. And you can always edit your layout using the XML editor, which IMHO will give you the best understanding of your layout.

Upvotes: 1

donfuxx
donfuxx

Reputation: 11321

The google play meta-data element:

<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />

should be placed within <application> in the xml and not after that.

See also the google play services setup guide.

Upvotes: 2

Related Questions