简体   繁体   English

在Android中集成Admob时出错

[英]Error in integrating Admob in Android

I have a completed app and I tried adding admob. 我有一个完整的应用程序,我尝试添加admob。

I got the publisher id and I have added it in manifest file. 我获得了发布者ID,我已将其添加到清单文件中。 When I run in the device, the app works fine in all other activities. 当我在设备中运行时,该应用程序在所有其他活动中正常工作。 However, when I move to the activity where the admob ad has been placed, my app crashes, and in logcat it shows the following error: 但是,当我移动到放置了admob广告的活动时,我的应用程序崩溃,并且在logcat中它显示以下错误:

The major errors shown in the logcat are as follows: logcat中显示的主要错误如下:

04-06 20:22:30.627: ERROR/AndroidRuntime(2339): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mnn.image0114/com.menteon.speedimage0114.ResultPage}: android.view.InflateException: Binary XML file line #8: Error inflating class com.admob.ads.AdView 04-06 20:22:30.627:ERROR / AndroidRuntime(2339):java.lang.RuntimeException:无法启动活动ComponentInfo {com.mnn.image0114 / com.menteon.speedimage0114.ResultPage}:android.view.InflateException:Binary XML文件行#8:使com.admob.ads.AdView类出错

04-06 20:22:30.627: ERROR/AndroidRuntime(2339): Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class com.admob.ads.AdView 04-06 20:22:30.627:ERROR / AndroidRuntime(2339):引起:android.view.InflateException:二进制XML文件行#8:错误导入类com.admob.ads.AdView

04-06 20:22:30.627: ERROR/AndroidRuntime(2339): Caused by: java.lang.ClassNotFoundException: com.admob.ads.AdView in loader dalvik.system.PathClassLoader@44ccc270 04-06 20:22:30.627:ERROR / AndroidRuntime(2339):引起:java.lang.ClassNotFoundException:com.admob.ads.AdView in loader dalvik.system.PathClassLoader@44ccc270

How to fix this error? 如何解决这个错误? Please help me. 请帮我。

I had the same problem, and I fixed it following the instructions here: NoClassDefFoundError when GoogleAnalyticsTracker.getInstance() It seems the new version 17 of ADT requires the libraries to be imported from a "libs" folder inside your project. 我有同样的问题,我按照这里的说明修复它: NoAlassDefFoundError当GoogleAnalyticsTracker.getInstance()似乎ADT的新版本17要求从项目内的“libs”文件夹导入库。 So I just created the "libs" folder, imported my libs there, and then set them in the project's build path (basically following the instructions at the above link). 所以我刚刚创建了“libs”文件夹,在那里导入我的库,然后在项目的构建路径中设置它们(基本上按照上面链接中的说明)。 It fixed both problems I had with admob and analytics code. 它修复了我使用admob和分析代码时遇到的两个问题。

If you're using a recent AdMob jar, you need to be using com.google.ads.AdView . 如果您使用的是最近的AdMob jar,则需要使用com.google.ads.AdView This is certainly the case in Sdk 4.04. 在Sdk 4.04中肯定是这种情况。

Having said that, I didn't put my AdViews directly into the XML, but used the following code to place the ads inside a LinearLayout within my XML - 话虽如此,我没有将我的AdView直接放入XML中,而是使用以下代码将广告放入我的XML中的LinearLayout中 -

adView = new AdView(this, AdSize.BANNER, MY_ID);
LinearLayout layout = (LinearLayout) findViewById(R.id.adMob);
layout.addView(adView);
AdRequest adRequest = new AdRequest();
adRequest.setTesting(GlobalData.DebugBuild);
adView.loadAd(adRequest);

To solve this I created a folder called /libs and copied the GoogleAdMobAdsSdk-6.0.1.jar into it. 为了解决这个问题,我创建了一个名为/ libs的文件夹,并将GoogleAdMobAdsSdk-6.0.1.jar复制到其中。 Worked like a Charm. 像魅力一样工作。

Yeah I agree with Steve the Sultan. 是的,我同意苏丹的史蒂夫。 I've tried the method with some additional modification to the AdView widget in the layout file. 我已经尝试了该方法,并对布局文件中的AdView小部件进行了一些额外的修改。 And I got this, http://blog.kerul.net/2012/08/example-how-to-install-google-admob-6x.html ... 我得到了这个, http://blog.kerul.net/2012/08/example-how-to-install-google-admob-6x.html ...

I have this experience of having the apps crashing and displaying messages such as this - "Error inflating class com.admob.ads.AdView" . 我有这样的经验,让应用程序崩溃并显示诸如此类的消息 - “错误膨胀类com.admob.ads.AdView”。 Doing some research and testing I concluded the following XML attribute to display the AdView; 做了一些研究和测试我得出以下XML属性来显示AdView;

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@drawable/bg1"
android:orientation="vertical" >

<TableRow
    android:id="@+id/tableRow2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >
    <com.google.ads.AdView
        xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
        android:id="@+id/ad"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="738a44d913034b9f"
        />  
</TableRow>

<TableRow
    android:id="@+id/tableRow3"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <EditText
        android:id="@+id/txtsearch"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:inputType="textMultiLine"
        android:maxLines="3"
        android:minLines="1"
        android:scrollbarStyle="outsideOverlay"
        android:scrollbars="vertical" />

</TableRow>

<TableRow
    android:id="@+id/tableRow1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >







    <Button
        android:id="@+id/btnkamus"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawableRight="@drawable/search" />




    <Button
        android:id="@+id/btnsearch"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:text="Kesan" />


    <Button
        android:id="@+id/btncadang"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:text="Cadang" />

</TableRow>


<WebView
    android:id="@+id/webView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

</LinearLayout>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM