2014-08-31 82 views
0

我有异国情调的问题 没有错误在我的项目 如何解决这个问题恳求帮助 感谢所有帮助我 大家好 我有异国情调的问题 没有错误在我的项目 如何要解决这个问题恳求帮助 感谢所有帮助我当添加AdMob广告代码,以我的应用程序

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. 

layout.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:ads="http://schemas.android.com/apk/lib/com.google.android.gms.ads " 
       android:orientation="vertical" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
               > 

    <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="xxxxxxxxxxxxxxxxxxx" 

     /> 
</LinearLayout> 

的manifest.xml

<?xml version="1.0" encoding="utf-8"?> 
<manifest 
    xmlns:android="http://schemas.android.com/apk/res/android" 
      package="com.test.admobapp" 
      android:versionCode="1" 
      android:versionName="1.0"> 
    <uses-sdk 
     android:minSdkVersion="9" 
       android:targetSdkVersion="18" /> 

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
    <uses-permission android:name="android.permission.INTERNET"/> 

    <application 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name"> 
     <activity android:name=".BannerXMLSample" 
        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"/> 

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


</manifest> 

MainAcitvity.java

package com.test.admobapp; 
import com.google.android.gms.ads.AdRequest; 
import com.google.android.gms.ads.AdView; 
import android.support.v7.app.ActionBarActivity; 
import android.os.Bundle; 
import android.view.Menu; 
import android.view.MenuItem; 

public class MainActivity extends ActionBarActivity { 
    private static final String TEST_DEVICE_ID = "xxxxxxxxxxxxxxxxxxxx"; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     AdView adView = (AdView) this.findViewById(R.id.adView); 
      AdRequest adRequest = new AdRequest.Builder() 
       .addTestDevice(AdRequest.DEVICE_ID_EMULATOR) 
       .addTestDevice(TEST_DEVICE_ID) 
       .build(); 
      adView.loadAd(adRequest); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.main, menu); 
     return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     // Handle action bar item clicks here. The action bar will 
     // automatically handle clicks on the Home/Up button, so long 
     // as you specify a parent activity in AndroidManifest.xml. 
     int id = item.getItemId(); 
     if (id == R.id.action_settings) { 
      return true; 
     } 
     return super.onOptionsItemSelected(item); 
    } 
} 

回答

-1

可以在layout.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       xmlns:ads="http://schemas.android.com/apk/lib/com.google.android.gms.ads" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:id="@+id/adView" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" /> 
    </LinearLayout> 
</LinearLayout> 
0

使用这样如果没有更详细的该日志信息,那么它意味着您没有将Google Play服务库添加到您的APK中。

相关问题