Search code examples
androidprogress-barseekbarcountdowntimershutdown

Android ProgressBar Shut Down Application


I am developing a beginner level android application. I am using CountDownTimer and ProgressBar together. But the application closes when I use another progress bar for a different task. I cannot even use a SeekBar or ProgressBar.

I need to use another CountDownTimer with ProgressBar. The application closes when I call the required function in the Java.

Note: Both of countdown will work without progress bar.

private void ExamleSeekBar() {...}

    seekBar=(SeekBar)findViewById(R.id.seekBar);
    seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress,
                                      boolean fromUser) {
            Toast.makeText(getApplicationContext(),"seekbar progress: "+progress, Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            Toast.makeText(getApplicationContext(),"seekbar touch started!", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            Toast.makeText(getApplicationContext(),"seekbar touch stopped!", Toast.LENGTH_SHORT).show();
        }

Erorr:

07-05 05:34:00.515 1792-5244/? W/audio_hw_generic: Hardware backing HAL too slow, could only write 0 of 720 frames
07-05 05:34:00.533 6610-6610/sengoz.yavuz.MyApp D/AndroidRuntime: Shutting down VM
07-05 05:34:00.535 1792-5244/? W/audio_hw_generic: Hardware backing HAL too slow, could only write 0 of 720 frames
07-05 05:34:00.556 6610-6610/sengoz.yavuz.MyApp E/AndroidRuntime: FATAL EXCEPTION: main
    Process: sengoz.yavuz.MyApp, PID: 6610
    java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.SeekBar.setOnSeekBarChangeListener(android.widget.SeekBar$OnSeekBarChangeListener)' on a null object reference
        at sengoz.yavuz.MyApp.MainActivity.ExamleSeekBar(MainActivity.java:1472)
        at sengoz.yavuz.MyApp.MainActivity.ScoreDialog(MainActivity.java:1322)
        at sengoz.yavuz.MyApp.MainActivity.access$1500(MainActivity.java:32)
        at sengoz.yavuz.MyApp.MainActivity$9$7.onClick(MainActivity.java:1079)
        at android.view.View.performClick(View.java:6597)
        at android.view.View.performClickInternal(View.java:6574)
        at android.view.View.access$3100(View.java:778)
        at android.view.View$PerformClick.run(View.java:25883)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6642)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

Solution

  • You have a nullPointerException on seekbar ui controller. Check if seekbar is added in the same layout you set as parameter in setContentView(R.layout.<your_layout>)

    Update you're code with onCreate method and xml code.