当我尝试将广告放入它时,应用程序强制关闭

问题描述:

我正在创建一个应用程序。这是部队尽快结束,因为我尝试去到包含当我尝试将广告放入它时,应用程序强制关闭

<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

使用,不要硬编码的谷歌游戏服务的版本号。使用@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

+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

如果您的应用程序,由于最新的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

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服务,方法是选中复选框