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.

1
  • did you add that admob jar file? Apr 6, 2011 at 15:27

4 Answers 4

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.

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);
7
  • what is this GlobalData....i tried using your answer but got red lines in those words
    – Siva K
    Apr 7, 2011 at 4: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 7, 2011 at 7:29
  • can you pls answer my question in the following link stackoverflow.com/questions/5576516/…
    – Siva K
    Apr 7, 2011 at 7: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 7, 2011 at 8:04
  • sorry i have found answer for one issue only ...pls answer in this link stackoverflow.com/questions/5577958/….... pls help me
    – Siva K
    Apr 7, 2011 at 8:16
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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.