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 7002741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:58:04+00:00 2026-05-27T20:58:04+00:00

Hello when I try to set the current progress of a seekbar that is

  • 0

Hello when I try to set the current progress of a seekbar that is a preference, based on the ringer volumes current level in onResume I get the following:

12-31 22:02:12.559: E/AndroidRuntime(266): java.lang.RuntimeException: Unable to resume activity {com.camelCaseD.nsettings/com.camelCaseD.nsettings.Toggles}: java.lang.NullPointerException
12-31 22:02:12.559: E/AndroidRuntime(266):  at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2120)
12-31 22:02:12.559: E/AndroidRuntime(266):  at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2135)
12-31 22:02:12.559: E/AndroidRuntime(266):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1668)
12-31 22:02:12.559: E/AndroidRuntime(266):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
12-31 22:02:12.559: E/AndroidRuntime(266):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
12-31 22:02:12.559: E/AndroidRuntime(266):  at android.os.Handler.dispatchMessage(Handler.java:99)
12-31 22:02:12.559: E/AndroidRuntime(266):  at android.os.Looper.loop(Looper.java:123)
12-31 22:02:12.559: E/AndroidRuntime(266):  at android.app.ActivityThread.main(ActivityThread.java:3683)
12-31 22:02:12.559: E/AndroidRuntime(266):  at java.lang.reflect.Method.invokeNative(Native Method)
12-31 22:02:12.559: E/AndroidRuntime(266):  at java.lang.reflect.Method.invoke(Method.java:507)
12-31 22:02:12.559: E/AndroidRuntime(266):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-31 22:02:12.559: E/AndroidRuntime(266):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-31 22:02:12.559: E/AndroidRuntime(266):  at dalvik.system.NativeStart.main(Native Method)
12-31 22:02:12.559: E/AndroidRuntime(266): Caused by: java.lang.NullPointerException
12-31 22:02:12.559: E/AndroidRuntime(266):  at com.camelCaseD.nsettings.SeekBarPreference.setProgressC(SeekBarPreference.java:215)
12-31 22:02:12.559: E/AndroidRuntime(266):  at com.camelCaseD.nsettings.Toggles.onResume(Toggles.java:112)
12-31 22:02:12.559: E/AndroidRuntime(266):  at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1150)
12-31 22:02:12.559: E/AndroidRuntime(266):  at android.app.Activity.performResume(Activity.java:3832)
12-31 22:02:12.559: E/AndroidRuntime(266):  at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2110)
12-31 22:02:12.559: E/AndroidRuntime(266):  ... 12 more

Here is the SeekBarPreference Class:

import com.camelCaseD.nsettings.R;

import android.content.Context;
import android.content.res.TypedArray;
import android.preference.Preference;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SeekBar;
import android.widget.TableLayout;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import android.media.AudioManager;

public class SeekBarPreference extends Preference implements OnSeekBarChangeListener {

    private final String TAG = getClass().getName();

    private static final int DEFAULT_VALUE = 50;

    private int mMinValue      = 0;
    private int mCurrentValue;
    private SeekBar mSeekBar;

    private AudioManager mgr=null;

    private View mView;

    private int mStream;

    public SeekBarPreference(Context context, AttributeSet attrs, int stream) {
        super(context, attrs);

        mStream = stream;
    }

    public SeekBarPreference(Context context, AttributeSet attrs, int defStyle, int stream) {
        super(context, attrs, defStyle);

        mStream = stream;
    }

    @Override
    protected View onCreateView(ViewGroup parent){

        TableLayout layout =  null;

        try {
            LayoutInflater mInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            layout = (TableLayout)mInflater.inflate(R.layout.seek_bar_preference, parent, false);
        }
        catch(Exception e)
        {
            Log.e(TAG, "Error creating seek bar preference", e);
        }

        return layout;

    }

    private void initBar(SeekBar bar, final int stream, View view) {
        mgr=(AudioManager)getContext().getSystemService(Context.AUDIO_SERVICE);

        bar.setMax(mgr.getStreamMaxVolume(stream));
        bar.setProgress(mgr.getStreamVolume(stream));

        TextView mTitle = (TextView) view.findViewById(android.R.id.title);
        TextView mSummary = (TextView) view.findViewById(android.R.id.summary);

        switch(stream) {
        case AudioManager.STREAM_RING:
            mTitle.setText("Ringer Volume");
            mSummary.setText("Slide to adjust ringer volume.");
            break;

        case AudioManager.STREAM_MUSIC:
            mTitle.setText("Media Volume");
            mSummary.setText("Slide to adjust media volume.");
            break;
        }

        bar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
          public void onProgressChanged(SeekBar bar, int progress,
                                        boolean fromUser) {
            mgr.setStreamVolume(stream, progress,
                                AudioManager.FLAG_PLAY_SOUND);
          }

          public void onStartTrackingTouch(SeekBar bar) {
            // no-op
          }

          public void onStopTrackingTouch(SeekBar bar) {
            // no-op
          }
        });
      }

    @Override
    public void onBindView(View view) {
        super.onBindView(view);
        try
        {
            mView = view;
            mSeekBar = (SeekBar) view.findViewById(R.id.seek_bar);
            initBar(mSeekBar, mStream, view);
        }
        catch(Exception ex) {
            Log.e(TAG, "Error binding view: " + ex.toString());
        }

        updateView(view);
    }

    /**
     * Update a SeekBarPreference view with our current state
     * @param view
     */
    protected void updateView(View view) {

        try {
            TableLayout layout = (TableLayout)view;

            mSeekBar.setProgress(mCurrentValue - mMinValue);
        }
        catch(Exception e) {
            Log.e(TAG, "Error updating seek bar preference", e);
        }

    }

    @Override 
    protected Object onGetDefaultValue(TypedArray ta, int index){

        int defaultValue = ta.getInt(index, DEFAULT_VALUE);
        return defaultValue;

    }

    @Override
    protected void onSetInitialValue(boolean restoreValue, Object defaultValue) {

    }

    public void setProgressC(int stream) {
        mgr=(AudioManager)getContext().getSystemService(Context.AUDIO_SERVICE);
        switch(stream) {
        case AudioManager.STREAM_RING:
            SeekBar bar = (SeekBar)mView.findViewById(R.id.seek_bar);
            bar.setProgress(mgr.getStreamVolume(AudioManager.STREAM_RING));
            break;
        }
    }

}

The view class extends Preference and the layout of the view is shown below:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res/com.commonsware.android.syssvc.volume"
  android:stretchColumns="1"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:paddingLeft="20px"
  android:paddingRight="10px"
>
  <TableRow android:paddingTop="10px" 
            android:paddingBottom="2px" >
            <TextView android:id="@android:id/title" android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textSize="22dp"
            android:typeface="sans"
            android:textStyle="normal"
            android:textColor="#ffffff" />
  </TableRow>
  <TableRow android:paddingTop="2px" 
            android:paddingBottom="2px" >
  <TextView android:id="@android:id/summary" 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
  </TableRow>
  <TableRow
    android:paddingBottom="20px">
    <SeekBar
      android:id="@+id/seek_bar"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
    />
   </TableRow>  
</TableLayout>

Then inside my PreferenceActivity class:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    PreferenceCategory mAudCat = (PreferenceCategory) findPreference("audCat");

    SeekBarPreference mRingerVol = new SeekBarPreference(this, null, AudioManager.STREAM_RING);
    mRingerVol.setKey("ringerVol");

    mAudCat.addPreference(mRingerVol);
}

@Override
public void onResume() {
    super.onResume();

    SeekBarPreference mRingerVol = (SeekBarPreference) findPreference("ringerVol");
    mRingerVol.setProgressC(AudioManager.STREAM_RING);
}

Any help will be greatly appreciated.

  • 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-27T20:58:05+00:00Added an answer on May 27, 2026 at 8:58 pm

    How I have figured the source of the error.

    In setProgressC the variable mView is null after I outputted the value of this variable in onBindView and setProgressC itself into LogCat.

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

Sidebar

Related Questions

I try this in PHPMyadmin: Update wp_1_posts SET post_content='<strong>Hello </strong> <a href=http://stackoverflow.com>stackoverflow</a> you think
When I try to read my cookie that I have set something does not
Hello I am trying to set up a MyBB Forum. I tried to get
When I try this code: dict_a = dict_b = dict_c = {} dict_c['hello'] =
HttpRequestValidationException occurs when I try post when txtBulletin contains any HTML, like Hello<br />World
First off - hello, this is my first Stack Overflow question so I'll try
I have a C++ DLL with code like this: LogMessage( Hello world ); try
Hello I have the following error by git-fsck, which cannot be cleaned by git-gc
Hello again ladies and gents! OK, following on from my other question on ASP.NET
Hello I am compiling a program with make but I get the error of

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.