添加admob后,Android应用无法启动

添加admob后,Android应用无法启动,第1张

概述我正在尝试在我的应用程序中实现admob,但是在添加它之后应用程序无法启动.这是活动代码:http://code.google.com/p/zhuang-dict/source/browserunk/ZhuangDict/src/cn/wangdazhuang/zdict/ZhuangDictActivity.javamain.xml:<?xmlversion="1.0"encoding="utf-8"?><LinearLay

我正在尝试在我的应用程序中实现admob,但是在添加它之后应用程序无法启动.

这是活动代码:
http://code.google.com/p/zhuang-dict/source/browse/trunk/ZhuangDict/src/cn/wangdazhuang/zdict/ZhuangDictActivity.java

main.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.ads"    androID:orIEntation="vertical"    androID:layout_wIDth="fill_parent"    androID:layout_height="fill_parent"    >    <relativeLayout        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"    >        <Imagebutton            androID:ID="@+ID/ts"            androID:contentDescription="@string/tts_contentDescription"            androID:layout_wIDth="wrap_content"             androID:layout_height="wrap_content"            androID:layout_alignParentRight="true"             androID:src="@androID:drawable/ic_btn_speak_Now"        />        <Imagebutton            androID:ID="@+ID/search"            androID:contentDescription="@string/search_contentDescription"            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:layout_toleftOf="@ID/ts"            androID:src="@androID:drawable/ic_search_category_default"        />        <autoCompleteTextVIEw            androID:ID="@+ID/edit"            androID:layout_wIDth="fill_parent"             androID:layout_height="wrap_content"             androID:focusable="true"            androID:singleline="true"            androID:layout_toleftOf="@ID/search"            androID:hint="@string/edit_hint"        />    </relativeLayout>    <WebVIEw        androID:ID="@+ID/result"        androID:layout_wIDth="fill_parent"        androID:layout_height="fill_parent"    />    <com.Google.ads.AdVIEw androID:ID="@+ID/adVIEw"                     androID:layout_wIDth="wrap_content"                     androID:layout_height="wrap_content"                     ads:adUnitID="myID"                     ads:adSize="BANNER"                     ads:loadAdOnCreate="true"     /></linearLayout>

解决方法:

你有没有把它添加到你的清单?

    <activity androID:name="com.Google.ads.AdActivity"          androID:configChanges="keyboard|keyboardHIDden|orIEntation|screenLayout|uiMode|screenSize|smallestScreenSize"/>

如谷歌教程中所示:

    <com.Google.ads.AdVIEw androID:ID="@+ID/adVIEw"                     androID:layout_wIDth="wrap_content"                     androID:layout_height="wrap_content"                     ads:adUnitID="MY_AD_UNIT_ID"                     ads:adSize="BANNER"                     ads:testDevices="TEST_EMulATOR, TEST_DEVICE_ID"                     ads:loadAdOnCreate="true"/>

adUnitID必须是您的应用的ID,您是否设置了此ID或者您是否真的在上面显示的代码中设置了“myID”?

编辑

以下是一些其他信息,似乎所有AdMob lib都没有捆绑到您的项目中.这可能导致许多不同的原因.阅读步骤并确保,您确实已经完成了这项工作,如果没有,请执行此 *** 作:

更新Eclipse和AndroID SDK:

>以管理员身份打开Eclipse
>转到帮助 – >检查更新并运行更新
>设置检查下一个窗口中显示的所有内容.没有必要,但更新全部并不是错误的
>接受条款和被许可人并按完成…更新将开始并需要一些时间
>如果更新完成,请将Eclipse重新启动为admin.您可能会收到一条错误消息,指出并非所有更新都可以完成…前进

更新AndroID SDK:

>在Eclipse goto Window – > AndroID SDK Manager中
>在“状态”列中您可以看到更新是否可用.选择所有更新……
>如果完成,请再次重启Eclipse

使用Admob – 放置jar文件并设置路径:

>从谷歌网站下载AdMob SDK(可能是一个不同的链接取决于国家)
https://developers.google.com/mobile-ads-sdk/download?hl=de
>将文件解压缩到一个目录中(无论在哪里)
>在Eclispe的项目中创建一个“libs”文件夹.
请确保文件夹被命名为“libs”而不是“lib”.这个错误已经完成了

>将jar文件从admob文件夹复制到您的项目中的libs文件夹中
>在lib文件夹内的jar文件上单击鼠标右键,然后选择Build Path – > add to build path
>要确保一切都已完成,请在项目上单击鼠标右键,然后选择属性
>选择Java-Build-Path并转到librarIEs选项卡
>选择添加外部jar并从admob文件夹中选择此jar
>选择确定

开始吧

>把它放到你的Manifest.xml中

<activity androID:name="com.Google.ads.AdActivity"   androID:configChanges="keyboard|keyboardHIDden|orIEntation|screenLayout|uiMode|screenSize|smallestScreenSize"/> </application>

您的Manifest.xml应该类似于:

       <?xml version="1.0" enCoding="utf-8"?>         <manifest xmlns:androID="http://schemas.androID.com/apk/res/androID"          package="com.company"          androID:versionCode="1" androID:versionname="1.0">       <application androID:icon="@drawable/icon" androID:label="@string/app_name"           androID:deBUGgable="true">       <activity androID:label="@string/app_name" androID:name="BannerExample">           <intent-filter>           <action androID:name="androID.intent.action.MAIN"/>            <category androID:name="androID.intent.category.LAUNCHER"/>             </intent-filter>       </activity>      <activity androID:name="com.Google.ads.AdActivity"             androID:configChanges="keyboard|keyboardHIDden|orIEntation|screenLayout|uiMode|screenSize|smallestScreenSize"/>        </application>        </manifest>

注意:将此行置于您的活动之上,而不是在您的活动之内

>在manifest.xml中设置权限

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

>创建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.ads"      androID:orIEntation="vertical"      androID:layout_wIDth="fill_parent"      androID:layout_height="fill_parent">    <com.Google.ads.AdVIEw androID:ID="@+ID/adVIEw"                 androID:layout_wIDth="wrap_content"                 androID:layout_height="wrap_content"                 ads:adUnitID="MY_AD_UNIT_ID"                 ads:adSize="BANNER"                 ads:testDevices="TEST_EMulATOR, TEST_DEVICE_ID"                 ads:loadAdOnCreate="true"/>   </linearLayout>

>此外,如果上述步骤不起作用,您可以在您想要显示admob的活动中执行此 *** 作.请参阅您的活动的onCreate()中的admob xml ID:

    public class AdMobActivity extends Activity {   private AdVIEw adVIEw;    @OverrIDe    public voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);            setContentVIEw(R.layout.main);        // Create the adVIEw   adVIEw = new AdVIEw(this, AdSize.BANNER, MY_AD_UNIT_ID);       // Lookup your linearLayout assuming it’s been given      // the attribute androID:ID="@+ID/mainLayout"    linearLayout layout = (linearLayout)findVIEwByID(R.ID.mainLayout);       // Add the adVIEw to it     layout.addVIEw(adVIEw);       // Initiate a generic request to load it with an ad    adVIEw.loadAd(new AdRequest());     }

在我的应用程序中,我已经完成了两者,通常只需要在XML或Code中执行它,但两者都可以正常工作.

总结

以上是内存溢出为你收集整理的添加admob后,Android应用无法启动全部内容,希望文章能够帮你解决添加admob后,Android应用无法启动所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1102408.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存