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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:23:50+00:00 2026-06-05T05:23:50+00:00

I am trying to run the seek bar while recording audio. Here is my

  • 0

I am trying to run the seek bar while recording audio.

Here is my code.

public class ServerAudioSendActivity extends Activity {

private Button buttonPlayStop;
private MediaPlayer mediaPlayer;
private SeekBar seekBar;

private final Handler handler = new Handler();

// Here i override onCreate method.
//
// setContentView() method set the layout that you will see then
// the application will starts
//
// initViews() method i create to init views components.
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main);
    initViews();

}

// This method set the setOnClickListener and method for it (buttonClick())
private void initViews() {
    buttonPlayStop = (Button) findViewById(R.id.ButtonPlayStop);
    buttonPlayStop.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            buttonClick();
        }
    });

    // mediaPlayer = MediaPlayer.create(this, R.raw.sound41772);

    seekBar = (SeekBar) findViewById(R.id.SeekBar01);
    seekBar.setMax(mediaPlayer.getDuration());
    seekBar.setOnTouchListener(new OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            seekChange(v);
            return false;
        }
    });

}

public void startPlayProgressUpdater() {
    seekBar.setProgress(mediaPlayer.getCurrentPosition());

    if (mediaPlayer.isPlaying()) {
        Runnable notification = new Runnable() {
            public void run() {
                startPlayProgressUpdater();
            }
        };
        handler.postDelayed(notification, 1000);
    } else {
        mediaPlayer.pause();
        buttonPlayStop.setText(getString(R.string.play_str));
        seekBar.setProgress(0);
    }
}

// This is event handler thumb moving event
private void seekChange(View v) {
    if (mediaPlayer.isPlaying()) {
        SeekBar sb = (SeekBar) v;
        mediaPlayer.seekTo(sb.getProgress());
    }
}

// This is event handler for buttonClick event
private void buttonClick() {
    if (buttonPlayStop.getText() == getString(R.string.play_str)) {
        buttonPlayStop.setText(getString(R.string.pause_str));
        try {
            mediaPlayer.start();
            startPlayProgressUpdater();
        } catch (IllegalStateException e) {
            mediaPlayer.pause();
        }
    } else {
        buttonPlayStop.setText(getString(R.string.play_str));
        mediaPlayer.pause();
    }
}
 }

Giving this error in logcat

06-06 17:57:33.522: W/dalvikvm(1068): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
06-06 17:57:33.542: E/AndroidRuntime(1068): FATAL EXCEPTION: main
06-06 17:57:33.542: E/AndroidRuntime(1068): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sendaudiotoserver/com.sendaudiotoserver.ServerAudioSendActivity}: java.lang.NullPointerException
06-06 17:57:33.542: E/AndroidRuntime(1068):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
06-06 17:57:33.542: E/AndroidRuntime(1068):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
 06-06 17:57:33.542: E/AndroidRuntime(1068):    at android.app.ActivityThread.access$600(ActivityThread.java:123)
 06-06 17:57:33.542: E/AndroidRuntime(1068):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
 06-06 17:57:33.542: E/AndroidRuntime(1068):    at android.os.Handler.dispatchMessage(Handler.java:99)
 06-06 17:57:33.542: E/AndroidRuntime(1068):    at android.os.Looper.loop(Looper.java:137)
 06-06 17:57:33.542: E/AndroidRuntime(1068):    at android.app.ActivityThread.main(ActivityThread.java:4424)
 06-06 17:57:33.542: E/AndroidRuntime(1068):    at java.lang.reflect.Method.invokeNative(Native Method)
 0 6-06 17:57:33.542: E/AndroidRuntime(1068):   at java.lang.reflect.Method.invoke(Method.java:511)
 06-06 17:57:33.542: E/AndroidRuntime(1068):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
 06-06 17:57:33.542: E/AndroidRuntime(1068):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
 0 6-06 17:57:33.542: E/AndroidRuntime(1068):   at dalvik.system.NativeStart.main(Native  Method)
 06-06 17:57:33.542: E/AndroidRuntime(1068): Caused by: java.lang.NullPointerException
 06-06 17:57:33.542: E/AndroidRuntime(1068):    at com.sendaudiotoserver.ServerAudioSendActivity.startPlayProgressUpdater(ServerAudioSendActivity.java:60)
 06-06 17:57:33.542: E/AndroidRuntime(1068):    at com.sendaudiotoserver.ServerAudioSendActivity.onCreate(ServerAudioSendActivity.java:32)
 06-06 17:57:33.542: E/AndroidRuntime(1068):    at android.app.Activity.performCreate(Activity.java:4465)
 06-06 17:57:33.542: E/AndroidRuntime(1068):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
 06-06 17:57:33.542: E/AndroidRuntime(1068):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
 06-06 17:57:33.542: E/AndroidRuntime(1068):    ... 11 more

please let me know where I am going wrong..

Many Thanks
Rahul

  • 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-05T05:23:51+00:00Added an answer on June 5, 2026 at 5:23 am

    You have commented this line:

    // mediaPlayer = MediaPlayer.create(this, R.raw.sound41772);
    

    Hence, you are getting a NullPointerException at :

    mediaPlayer.getDuration()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to run this code . Basically I want the https://admin:qwerty123@ '$dmp':7777/set_param?'$params command
I wrote this C program for Win32/c compiler but while i'm trying run this
I'm learning about Qt Model/View with Ruby and I'm trying run the following code
When trying run this code: At first it prints Process some_id BEFORE enter for
I'm trying to serialize/deserialize string. Using the code: private byte[] StrToBytes(string str) { BinaryFormatter
When I'm trying run below code in Oracle 11g , @?/rdbms/admin/prvtmail.plb I got this
Trying to run the Blocking Queue example given here . Using the .NET Queue
While trying to run the following snippet from Scala for the impatient : val
I am trying run a program from a qmake .pro file which modifies the
Situation: I'm trying run an https store (xcart) under one domain secure.example.com and I

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.