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

  • SEARCH
  • Home
  • 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 7975801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:44:41+00:00 2026-06-04T08:44:41+00:00

When I try to use a custom seekbar in main.xml I get failed to

  • 0

When I try to use a custom seekbar in main.xml I get failed to instantiate error message and while it is run it gives a Error inflating class message.

customseekbar.xml

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TableRow
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView 
        android:id="@+id/leftText"
        android:textSize="10dp"
        android:gravity="left" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

    <TextView 
        android:id="@+id/centerText"
        android:textSize="20dp"
        android:gravity="left"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView 
        android:id="@+id/rightText"
        android:textSize="10dp"
        android:gravity="right"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</TableRow>

<TableRow
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <SeekBar 
        android:id="@+id/seekBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"            />

</TableRow>

CustomSeekBar.java

    package kirbz.Component.CustomSeekBar;
    import android.content.Context;
    import android.util.AttributeSet;
    import android.widget.SeekBar;
    import android.widget.TextView;

public class CustomSeekBar extends SeekBar {

private SeekBar mSeekBar = (SeekBar) findViewById(R.id.seekBar);
private TextView mMinText = (TextView) findViewById(R.id.leftText);
private TextView mMaxText = (TextView) findViewById(R.id.rightText);
private TextView mValueText = (TextView) findViewById(R.id.centerText);

public CustomSeekBar(Context context, AttributeSet attrs) {
    super(context, attrs);
     mSeekBar=(SeekBar) findViewById(R.id.seekBar);
     mSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                mValueText.setText(String.valueOf(new Integer(progress)));        
            }

            public void onStartTrackingTouch(SeekBar arg0) {
                // TODO Auto-generated method stub
                  mValueText.setText(String.valueOf(new Integer(mSeekBar.getProgress())));      
            }

            public void onStopTrackingTouch(SeekBar arg0) {
                // TODO Auto-generated method stub
                  mValueText.setText(String.valueOf(new Integer(mSeekBar.getProgress())));      
            }
     });
    // TODO Auto-generated constructor stub
}

public void setValues(int max, int min, int value) {
    mSeekBar.setMax(max-min);
    mMaxText.setText(String.valueOf(max));
    mMinText.setText(String.valueOf(min));
    mSeekBar.setProgress(value - min);
    mValueText.setText(String.valueOf(value));

}

}

My main.xml is

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<kirbz.Component.CustomSeekBar.CustomSeekBar
    android:id="@+id/customSeekBar1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" 
    android:layout_gravity="left" />

LogCAT

05-01 17:39:51.227: E/AndroidRuntime(675): FATAL EXCEPTION: main
05-01 17:39:51.227: E/AndroidRuntime(675): java.lang.RuntimeException: Unable to start activity ComponentInfo{kirbz.Component.CustomSeekBar/kirbz.Component.CustomSeekBar.CustomSeekBarActivity}: android.view.InflateException: Binary XML file line #12: Error inflating class kirbz.Component.CustomSeekBar.CustomSeekBar
05-01 17:39:51.227: E/AndroidRuntime(675):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
05-01 17:39:51.227: E/AndroidRuntime(675):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
05-01 17:39:51.227: E/AndroidRuntime(675):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-01 17:39:51.227: E/AndroidRuntime(675):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
05-01 17:39:51.227: E/AndroidRuntime(675):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-01 17:39:51.227: E/AndroidRuntime(675):  at android.os.Looper.loop(Looper.java:123)
05-01 17:39:51.227: E/AndroidRuntime(675):  at android.app.ActivityThread.main(ActivityThread.java:3683)
05-01 17:39:51.227: E/AndroidRuntime(675):  at java.lang.reflect.Method.invokeNative(Native Method)
05-01 17:39:51.227: E/AndroidRuntime(675):  at java.lang.reflect.Method.invoke(Method.java:507)
05-01 17:39:51.227: E/AndroidRuntime(675):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-01 17:39:51.227: E/AndroidRuntime(675):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-01 17:39:51.227: E/AndroidRuntime(675):  at dalvik.system.NativeStart.main(Native Method)
05-01 17:39:51.227: E/AndroidRuntime(675): Caused by: android.view.InflateException: Binary XML file line #12: Error inflating class kirbz.Component.CustomSeekBar.CustomSeekBar
05-01 17:39:51.227: E/AndroidRuntime(675):  at android.view.LayoutInflater.createView(LayoutInflater.java:518)
05-01 17:39:51.227: E/AndroidRuntime(675):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
05-01 17:39:51.227: E/AndroidRuntime(675):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
05-01 17:39:51.227: E/AndroidRuntime(675):  at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
05-01 17:39:51.227: E/AndroidRuntime(675):  at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
05-01 17:39:51.227: E/AndroidRuntime(675):  at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
05-01 17:39:51.227: E/AndroidRuntime(675):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
05-01 17:39:51.227: E/AndroidRuntime(675):  at android.app.Activity.setContentView(Activity.java:1657)
05-01 17:39:51.227: E/AndroidRuntime(675):  at kirbz.Component.CustomSeekBar.CustomSeekBarActivity.onCreate(CustomSeekBarActivity.java:11)
05-01 17:39:51.227: E/AndroidRuntime(675):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-01 17:39:51.227: E/AndroidRuntime(675):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
05-01 17:39:51.227: E/AndroidRuntime(675):  ... 11 more
05-01 17:39:51.227: E/AndroidRuntime(675): Caused by: java.lang.reflect.InvocationTargetException
05-01 17:39:51.227: E/AndroidRuntime(675):  at java.lang.reflect.Constructor.constructNative(Native Method)
05-01 17:39:51.227: E/AndroidRuntime(675):  at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
05-01 17:39:51.227: E/AndroidRuntime(675):  at android.view.LayoutInflater.createView(LayoutInflater.java:505)
05-01 17:39:51.227: E/AndroidRuntime(675):  ... 21 more
05-01 17:39:51.227: E/AndroidRuntime(675): Caused by: java.lang.NullPointerException
05-01 17:39:51.227: E/AndroidRuntime(675):  at kirbz.Component.CustomSeekBar.CustomSeekBar.<init>(CustomSeekBar.java:18)
05-01 17:39:51.227: E/AndroidRuntime(675):  ... 24 more

Could you please advise what am I missing??

Appreciate your time and thanks in advance.

  • 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-06-04T08:44:43+00:00Added an answer on June 4, 2026 at 8:44 am

    I changed the entire approach and managed to achieve what I wanted with the following –

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
    
        <TableRow 
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
    
            <TextView 
                android:id="@+id/leftText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="10dp"
                android:gravity="left" android:layout_gravity="left|center_vertical" android:layout_weight="1" android:paddingLeft="10dp"/>
    
            <TextView 
                android:id="@+id/centerText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="20dp"
                android:gravity="center" android:layout_weight="1"/>
    
            <TextView 
                android:id="@+id/rightText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="10dp"
                android:gravity="right" android:layout_weight="1" android:paddingRight="10dp"/>
        </TableRow>
    
    
        <TableRow 
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
    
            <SeekBar 
                android:id="@+id/seekBar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
     />
    
        </TableRow>
    </LinearLayout>
    

    The CustomBar.java is the custom class that inflates the layout as a LAYOUT

    import android.content.Context;
    import android.util.AttributeSet;
    import android.view.LayoutInflater;
    import android.widget.LinearLayout;
    import android.widget.SeekBar;
    import android.widget.Toast;
    import android.widget.SeekBar.OnSeekBarChangeListener;
    import android.view.View;
    import android.widget.TextView;
    
    public class CustomBar extends LinearLayout {
    
        private SeekBar mSeekBar;
        private TextView mMinText;
        private TextView mMaxText;
        private TextView mValueText;
    
        public CustomBar(Context context, AttributeSet attrs) {
            super(context, attrs);
            final LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            inflater.inflate(R.layout.customseekbarlayout, this);
    
            initializeLayout();
    
            // TODO Auto-generated constructor stub
    
        }
    
        public void setValues(int max, int min, int value) {
            mSeekBar.setMax(max-min);
            mMaxText.setText(String.valueOf(max));
            mMinText.setText(String.valueOf(min));
            mSeekBar.setProgress(value - min);
            mValueText.setText(String.valueOf(value));
    
        }
    
        private void initializeLayout() {
            this.mSeekBar = (SeekBar) findViewById(R.id.seekBar);
            this.mMinText = (TextView) findViewById(R.id.leftText);
            this.mMaxText = (TextView) findViewById(R.id.rightText);
            this.mValueText = (TextView) findViewById (R.id.centerText);
    
            this.mSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
    
                @Override
                public void onProgressChanged(SeekBar seekBar, int progress,
                        boolean fromUser) {
                    // TODO Auto-generated method stub
                    mValueText.setText(String.valueOf(progress));
                }
    
                @Override
                public void onStartTrackingTouch(SeekBar seekBar) {
                    // TODO Auto-generated method stub
                    //Toast.makeText(getContext(), "Test2", Toast.LENGTH_SHORT).show();
                }
    
                @Override
                public void onStopTrackingTouch(SeekBar seekBar) {
                    // TODO Auto-generated method stub
                    //Toast.makeText(getContext(), "Test3", Toast.LENGTH_SHORT).show();
                }
    
            });
        }
    
        public int getValue(){
            return mSeekBar.getProgress();
        }
    
    
    }
    

    The main.xml is

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
        <kirbz.Components.CustomSeekBar.CustomBar
            android:id="@+id/customBar1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
        </kirbz.Components.CustomSeekBar.CustomBar>
    
    </LinearLayout>
    

    and the MainActivity is

    import android.app.Activity;
    import android.os.Bundle;
    
        public class CustomSeekBarActivity extends Activity {
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            final CustomBar mSeekBar = (CustomBar) findViewById(R.id.customBar1);
    
    
            mSeekBar.setValues(8,4,6);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to use your example to dynamically add/remove editor and get this error:
I try to use assignment_tag from django docs: https://docs.djangoproject.com/en/1.4/howto/custom-template-tags/#howto-custom-template-tags-simple-tags Test project: mysite/ manage.py polls/
I try to use doctest from example from http://docs.python.org/library/doctest.html But when I run python
I try to use the winDBG to debug a dump file. When I run
When I try to use custom taglibs in my webapp it doesn't work on
I've subclassed QGraphicsItem into my own custom class, Hexagon. When I try to use
I try to use enum type as a dependency property in my custom control,
I have a problem with Automapper when I try use custom resolver which uses
I try to use custom icons for the markers on my map. It works
When I try to use myCustomPanel.add(someComponent) it does not add... Here is my custom

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.