2014-11-22 53 views
0
<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" /> 

當我在圖形佈局中添加此代碼時會發現此錯誤,並且不會在設備上安裝應用程序。我怎麼解決這個問題?以下類無法實例化: - com.google.android.gms.ads

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) 
+0

您是否已將Google Play項目添加爲項目庫? – 2014-11-22 19:19:53

+0

是的谷歌播放項目添加 – student 2014-11-22 19:22:14

+0

請複製您的錯誤日誌。 – 2014-11-22 19:28:35

回答

2

確保你在你的佈局中定義正確的XML命名空間:

因此,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" /> 

在清單的應用程序標籤,不要忘了補充:

<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"/> 
+0

所有這些代碼writing.But它不安裝應用程序設備。 – student 2014-11-23 20:28:09

+0

對不起,但我不明白。確保你使用的是最新版本的庫,並且你已經引用了它並且做了一個項目清潔 – 2014-11-24 10:59:36

+0

謝謝,我確定最新版本。我把所有的東西都放回去了。 – student 2014-11-24 22:26:01

相關問題