student
student

Reputation: 1

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

<com.google.android.gms.ads.AdView
    android:id="@+id/adView"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    ads:adSize="BANNER"
    ads:adUnitId="ca-app-pub-32763440xxxxxxxxxxxx" />

When I add this code in the Graphical Layout turns out this error and does not install the application on the device. How can I solve this problem?

The following classes could not be instantiated:
  - com.google.android.gms.ads.AdView (Open Class, Show Error Log)
  See the Error Log (Window > Show View) for more details.
   java.lang.ClassNotFoundException: com.google.android.gms.R$styleable
     at java.net.URLClassLoader$1.run(    at java.net.URLClassLoader$1.run(    at            java.security.AccessController.doPrivileged(    at java.net.URLClassLoader.findClass(    at    java.lang.**strong text**ClassLoader.loadClass(    at java.lang.ClassLoader.loadClass(    at com.google.android.gms.internal.bb.<init>(    at com.google.android.gms.internal.bh.<init>(    at com.google.android.gms.internal.bh.<init>(    at com.google.android.gms.internal.bh.<init>(    at com.google.android.gms.ads.AdView.<init>(    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(    at sun.reflect.NativeConstructorAccessorImpl.newInstance(    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(    at java.lang.reflect.Constructor.newInstance(    at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.instantiateClass(ProjectCallback.java:442)
    at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.loadView(ProjectCallback.java:194)
    at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:207)
    at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:132)
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:806)
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:782)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:385)

Upvotes: 0

Views: 665

Answers (1)

Nana Ghartey
Nana Ghartey

Reputation: 7927

Make sure you have the right xml namespace defined in your layout:

Thus, xmlns:ads="http://schemas.android.com/apk/res-auto":

<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="50dp"
    ads:adSize="BANNER"
    ads:adUnitId="ca-app-pub-32763440xxxxxxxxxxxx" />

In the manifest's application tag, don't forget to add:

<activity android:name="com.google.android.gms.ads.AdActivity" 
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>`

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

Upvotes: 2

Related Questions