开发者

Error in integrating Admob in Android

I have a completed app and I tried adding admob.

I got the publisher id and I have added it in manifest file. 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:

The major errors shown in the logcat are as follows:

04-06 20:22:30.627: ERROR/AndroidRuntime(2339): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mnn.image01开发者_如何转开发14/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): 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): Caused by: 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. 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). It fixed both problems I had with admob and analytics code.


If you're using a recent AdMob jar, you need to be using com.google.ads.AdView. This is certainly the case in 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 = 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. 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. And I got this, 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" . Doing some research and testing I concluded the following XML attribute to display the 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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜