Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7563813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:45:38+00:00 2026-05-30T13:45:38+00:00

First, sorry for my English. I have a question when inflating layout: I have

  • 0

First, sorry for my English. I have a question when inflating layout:

I have a custom view, extends from a LinearLayout, called ButtonHelp. I use that view on my layout named LoadingActivity. My below codes work perfectly on every devices and emulators, except ones with QVGA screen like Samsung Galaxy Y with following errors:

FATAL EXCEPTION: main  
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp/com.myapp.LoadingActivity}: android.view.InflateException: Binary XML file line #45: Error inflating class com.myapp.customviews.ButtonHelp  
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)  
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)  
    at android.app.ActivityThread.access$1500(ActivityThread.java:117)  
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)  
    at android.os.Handler.dispatchMessage(Handler.java:99)  
    at android.os.Looper.loop(Looper.java:123)
    at android.app.ActivityThread.main(ActivityThread.java:3683)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #45: Error inflating class com.myapp.customviews.ButtonHelp
    at android.view.LayoutInflater.createView(LayoutInflater.java:518)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
    at android.app.Activity.setContentView(Activity.java:1657)
    at com.myapp.LoadingActivity.onCreate(LoadingActivity.java:45)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
    ... 11 more
Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Constructor.constructNative(Native Method)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
    at android.view.LayoutInflater.createView(LayoutInflater.java:505)
    ... 21 more
Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class android.widget.ImageButton
    at android.view.LayoutInflater.createView(LayoutInflater.java:518)
    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
    at com.myapp.customviews.ButtonHelp.initLayout(ButtonHelp.java:29)
    at com.myapp.customviews.ButtonHelp.<init>(ButtonHelp.java:17)
    ... 24 more
Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Constructor.constructNative(Native Method)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
    at android.view.LayoutInflater.createView(LayoutInflater.java:505)
    ... 32 more
Caused by: java.lang.StackOverflowError
    at android.util.LongSparseArray.get(LongSparseArray.java:79)
    at android.content.res.Resources.getCachedDrawable(Resources.java:1746)
    at android.content.res.Resources.loadDrawable(Resources.java:1664)
    at android.content.res.Resources.getDrawable(Resources.java:581)
    at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:162)
    at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:787)
    at android.graphics.drawable.Drawable.createFromXml(Drawable.java:728)
    at android.content.res.Resources.loadDrawable(Resources.java:1694)
    at android.content.res.Resources.getDrawable(Resources.java:581)
    at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:162)
    at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.

The problem is, I have no idea about this line:

Caused by: java.lang.StackOverflowError
    at android.util.LongSparseArray.get(LongSparseArray.java:79)

Why does it happen on QVGA emulators/devices?

FYI:

  • I have image resources for screen 320×480 only.
  • ButtonHelp layout:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical" >
    
    <ImageButton
        android:id="@+id/btnhelp_help"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_marginTop="5dp"
        android:background="@drawable/loading_button_help"
        android:src="@drawable/loading_icon_help" />
    </LinearLayout>
    
  • ButtonHelp code:

    public class ButtonHelp extends LinearLayout {
        private ImageButton mHelp;
    
        public ButtonHelp(Context context, AttributeSet attrs) {
            super(context, attrs);
            initLayout();
            initControls();
        }
    
        public ButtonHelp(Context context) {
            super(context);
            initLayout();
            initControls();
        }
    
        private void initLayout() {
            LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            inflater.inflate(R.layout.btn_help, this);
        }
    
        private void initControls() {
            mHelp = (ImageButton) findViewById(R.id.btnhelp_help);
        }
    
        public void setOnClickListener(View.OnClickListener listener) {
            mHelp.setOnClickListener(listener);
        }
    }
    
  • ButtonHelp is used in LoadingActivity:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/RelativeLayout1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/loading_background"
        android:orientation="vertical" >
    
    ...
    
        <com.myapp.customviews.ButtonHelp
            android:id="@+id/loading_help"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true" />
    
    ...
    
    </RelativeLayout>
    
  • When I remove ButtonHelp, the error still appears when creating layout, just like above logcat.

I’ve searched another SO questions but still have no solution or explanation for this case.

Many thanks!


UPDATE:

As asked, below are codes for loading_button_help:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_window_focused="false" android:state_enabled="true"
        android:drawable="@drawable/loading_button_help" /> <!-- Normal -->

    <item android:state_window_focused="false" android:state_enabled="false"
        android:drawable="@drawable/loading_button_help" /> <!--  Normal disable -->

    <item android:state_pressed="true" 
        android:drawable="@drawable/loading_button_help_press" /> <!-- pressed -->

    <item android:state_focused="true" android:state_enabled="true"
        android:drawable="@drawable/loading_button_help" /> <!-- selected -->

    <item android:state_enabled="true"
        android:drawable="@drawable/loading_button_help" /> <!-- normal -->

    <item android:state_focused="true"
        android:drawable="@drawable/loading_button_help" /> <!-- normal disable focused -->

    <item
        android:drawable="@drawable/loading_button_help" /> <!-- normal disable -->
</selector>

And loading_icon_help is just a PNG image.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T13:45:39+00:00Added an answer on May 30, 2026 at 1:45 pm

    In loading_button_help.xml you use @drawable/loading_button_help? I think you have cyclic reference. Try to rename your xml or image file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

at first, sorry about my english. My question is: I have php generated dynamic
Sorry, this's my first time to ask a question here. So, I don't have
First, sorry for my English, im not an American. My question is how can
first of all sorry for my English :-) not so good. I have a
First thing, sorry for my English. I have two forms in index. Login form
First of all, sorry for my bad english. I'll try to explain my question:
First of all, sorry for my English... I have something like this: public class
Ok First have all i'm sorry for my poor english :) Now for my
First sorry about my poor English. I used to use at git. git diff
first, sorry for the bad english. I have a test that submit a login

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.