2

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.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): 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.

Smi
  • 13,850
  • 9
  • 56
  • 64
Siva K
  • 4,968
  • 14
  • 82
  • 161

4 Answers4

8

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.

Community
  • 1
  • 1
Shumoapp
  • 1,489
  • 16
  • 15
5

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);
Rok
  • 2,568
  • 4
  • 26
  • 28
  • what is this GlobalData....i tried using your answer but got red lines in those words – Siva K Apr 07 '11 at 04:23
  • 1
    It's a flag I use to determine whether I'm making a release build or a debug build. Basically use `adRequest.setTesting(true)` for a debug build or `adRequest.setTesting(true)` for a release build – Rok Apr 07 '11 at 07:29
  • can you pls answer my question in the following link http://stackoverflow.com/questions/5576516/admob-cannot-be-viewed-in-android – Siva K Apr 07 '11 at 07:34
  • 1
    I meant `adRequest.setTesting(false)` for a release build. And it looks like you answered your own question from the above link? – Rok Apr 07 '11 at 08:04
  • sorry i have found answer for one issue only ...pls answer in this link http://stackoverflow.com/questions/5577958/admob-error-due-to-attrs-xml-in-android.... pls help me – Siva K Apr 07 '11 at 08:16
  • Is that the only solution? why doesn't it work any more to add it in the xml? – Ciprian Apr 07 '12 at 08:58
  • ok, found the fix here: http://android.okhelp.cz/noclassdeffounderror-com-google-ads-adview-adt-17/ – Ciprian Apr 07 '12 at 09:07
2

To solve this I created a folder called /libs and copied the GoogleAdMobAdsSdk-6.0.1.jar into it. Worked like a Charm.

1

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>