1

I am using AdMob in my main application. But when i start some service i get exception: android.view.InflateException: Binary XML file line #134: Error inflating class <unknown>

main AdMob layout

<LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="bottom"
        android:orientation="vertical" >

        <com.google.ads.AdView
            xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
            android:id="@+id/adView"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            ads:adSize="SMART_BANNER"
            ads:adUnitId="xxx"
            android:gravity="bottom" />
    </LinearLayout>

and then when i run service which call this code:

private View getMainLayout() {
        LayoutInflater inflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
        View layout = inflater.inflate(R.layout.main, null);

        return layout;
    }

i get exception:

01-26 07:55:56.500: W/dalvikvm(21075): threadid=1: thread exiting with uncaught exception (group=0x40c7a1f8)
01-26 07:55:56.655: E/AndroidRuntime(21075): FATAL EXCEPTION: main
01-26 07:55:56.655: E/AndroidRuntime(21075): java.lang.RuntimeException: Unable to create service com.xxx.sss.service.SmsService: android.view.InflateException: Binary XML file line #134: Error inflating class <unknown>
01-26 07:55:56.655: E/AndroidRuntime(21075):    at android.app.ActivityThread.handleCreateService(ActivityThread.java:2274)
01-26 07:55:56.655: E/AndroidRuntime(21075):    at android.app.ActivityThread.access$1600(ActivityThread.java:127)
01-26 07:55:56.655: E/AndroidRuntime(21075):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1212)
01-26 07:55:56.655: E/AndroidRuntime(21075):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-26 07:55:56.655: E/AndroidRuntime(21075):    at android.os.Looper.loop(Looper.java:137)
01-26 07:55:56.655: E/AndroidRuntime(21075):    at android.app.ActivityThread.main(ActivityThread.java:4511)
01-26 07:55:56.655: E/AndroidRuntime(21075):    at java.lang.reflect.Method.invokeNative(Native Method)
01-26 07:55:56.655: E/AndroidRuntime(21075):    at java.lang.reflect.Method.invoke(Method.java:511)
01-26 07:55:56.655: E/AndroidRuntime(21075):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
01-26 07:55:56.655: E/AndroidRuntime(21075):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
01-26 07:55:56.655: E/AndroidRuntime(21075):    at dalvik.system.NativeStart.main(Native Method)
01-26 07:55:56.655: E/AndroidRuntime(21075): Caused by: android.view.InflateException: Binary XML file line #134: Error inflating class <unknown>
01-26 07:55:56.655: E/AndroidRuntime(21075):    at android.view.LayoutInflater.createView(LayoutInflater.java:606)
01-26 07:55:56.655: E/AndroidRuntime(21075):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
01-26 07:55:56.655: E/AndroidRuntime(21075):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
01-26 07:55:56.655: E/AndroidRuntime(21075):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
01-26 07:55:56.655: E/AndroidRuntime(21075):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
01-26 07:55:56.655: E/AndroidRuntime(21075):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
01-26 07:55:56.655: E/AndroidRuntime(21075):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
01-26 07:55:56.655: E/AndroidRuntime(21075):    at com.xxx.sss.service.SmsService.getMainLayout(SmsService.java:79)
01-26 07:55:56.655: E/AndroidRuntime(21075):    at com.xxx.sss.service.SmsService.setOnLabelOnButton(SmsService.java:68)
01-26 07:55:56.655: E/AndroidRuntime(21075):    at com.xxx.sss.service.SmsService.onCreate(SmsService.java:37)
01-26 07:55:56.655: E/AndroidRuntime(21075):    at android.app.ActivityThread.handleCreateService(ActivityThread.java:2264)

what is wrong?

4
  • can you point out line 134 in xml? Commented Jan 26, 2013 at 7:12
  • line 134 is <com.google.ads.AdView Commented Jan 26, 2013 at 11:52
  • yes it is. Library is added in libs folder Commented Jan 26, 2013 at 14:39
  • I'm seeing the same, but only for a very small section of the users. None of them seems to be rooted, but still suspect some ad-blocking modification on their part. Commented Oct 29, 2013 at 22:46

2 Answers 2

1

You can also try this add dependency: compile 'com.google.android.gms:play-services-ads:8.4.+' to your app level build.gradel and build the project.

and then in your layout.xml file add

<com.google.android.gms.ads.AdView
                    android:id="@+id/adView"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="true"
                    android:layout_centerHorizontal="true"
                    ads:adSize="BANNER"
                    ads:adUnitId="@string/banner_ad_unit_id"/>

banner_ad_unit_id: this must be your unique id

add bellow line to your java file java file

mAdView = (AdView) mMainView.findViewById(R.id.adView); 

do not forget to add AdActivity in a manifest file.

Sign up to request clarification or add additional context in comments.

Comments

0

did you forget to declare com.google.ads.AdView library in manifest file?

1 Comment

this i have in my <activity android:name="com.google.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.