2014-11-24 51 views
0

我正在創建一個應用程序。這是部隊儘快結束,因爲我嘗試去到包含當我嘗試將廣告放入它時,應用程序強制關閉

<com.google.android.gms.ads.adview 
....... 
/> 

我已經安裝了谷歌從SDK管理髮揮服務,並添加了谷歌播放services.jar文件到我的構建路徑的活動。注意。我使用的是Eclipse而不是android Studio。

我的Manifest.xml。我宣佈INTERNET權限標籤: -

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.example.additiontables" 
android:versionCode="1" 
android:versionName="1.0" > 
<uses-permission android:name="android.permission.INTERNET" /> 

<uses-sdk 
    android:minSdkVersion="8" 
    android:targetSdkVersion="21" /> 

<application 

    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 


    <activity 
     android:name=".Addition_Tables" 
     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=".About_Me" 
     android:label="@string/title_activity_about__me" > 
    </activity> 
    <meta-data 
    android:name="com.google.android.gms.version" 
    android:value="6111000" /> 

<activity 
    android:name="com.google.android.gms.ads.AdActivity" 
    android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" 
    android:theme="@android:style/Theme.Translucent" /> 
</application> 

這裏是我的Activity.xml文件: - 我不知道我是否有運用com.google.android.gms.ads.AdView或只是com.google.ads.AdView.-

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
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.additiontables.About_Me" > 

<com.google.android.gms.ads.AdView 
    xmlns:googleads="http://schemas.android.com/apk/lib/com.google.ads" 
    android:id="@+id/ad" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    googleads:adSize="BANNER" 
    googleads:adUnitId="(My Id)" /> 

我很懊惱。:(

請幫助。

感謝提前:)

注意。我在Refrenced庫中有googleplayservices.jar。在你的Activity類

AdView adView = (AdView) this.findViewById(R.id.ad); 
    AdRequest adRequest = new AdRequest.Builder().build(); 
    adView.loadAd(adRequest); 

Admob

+0

使用播放存儲庫文件 – 2014-11-24 04:37:42

+3

粘貼您的logcat錯誤? – Dev 2014-11-24 04:38:01

+1

請提供您的logcat錯誤> – Bhadresh 2014-11-24 04:47:05

回答

1

使用,不要硬編碼的谷歌遊戲服務的版本號。使用@integer/google_play_services_version或它會拋出錯誤版本IllegalStateException

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

有關更多信息,請參見Setting Up Google Play Services

+0

我也收到錯誤之後。 – 2014-11-24 04:54:59

+0

可能是你的項目錯誤,現在admob不會給出任何錯誤 – 2014-11-24 04:58:02

+0

你是什麼意思? – 2014-11-24 04:59:02

3

+0

當我這樣做時,我得到一個錯誤,錯誤:錯誤:找不到匹配給定名稱的資源(在'值''整數/ google_play_services_version')。 – 2014-11-24 04:51:35

+0

我會嘗試清理和重新編譯,也看@我添加到答案的鏈接。 – iagreen 2014-11-24 04:56:34

+1

看着你的編輯,你不應該使用Eclipse引用jar,而應該引用一個庫項目。 – iagreen 2014-11-24 04:59:11

0

如果您的應用程序,由於最新的AdMob

TableRow TR = (TableRow) findViewById(R.id.TR); 
    AdView adView = new AdView(this); 
    adView.setAdSize(AdSize.BANNER); 
    adView.setAdUnitId(getString("your admob id here")); 
    AdRequest adRequest = new AdRequest.Builder().build(); 
    TR.addView(adView); 

    adView.loadAd(adRequest); 

XML代碼

<TableRow 
    android:id="@+id/TR" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_horizontal" 
    android:gravity="center_horizontal" /> 

清單文件

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

也是這個問題。 – 2014-11-24 05:22:56

0
private AdView adView; 
RelativeLayout view_for_ads; // take a relative layout in your layout at the bottom of screen 

在OnCreate中

崩潰,您可以使用另一種方法
adView = new AdView(this); 
adView.setAdSize(AdSize.BANNER); 
adView.setAdUnitId("your id"); 
AdRequest.Builder adRequestBuilder = new AdRequest.Builder(); 
view_for_ads = (RelativeLayout) findViewById(R.id.view_for_ads); 
view_for_ads.setVisibility(View.VISIBLE); 
view_for_ads.addView(adView); 
adView.loadAd(adRequestBuilder.build()); 

在XML

<RelativeLayout 
    android:id="@+id/view_for_ads" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" > 
</RelativeLayout> 

清單中

<uses-permission android:name="android.permission.INTERNET" /> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
<uses-permission android:name="android.permission.READ_PHONE_STATE" /> 
<uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS" /> 
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 

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

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

添加谷歌播放服務

右點擊 - >導入 - >現有的代碼 - > SDK \ \演員谷歌\ google_play_services 也會在工作區中添加GP服務,方法是選中複選框

相關問題