Android ProgressBar 关闭应用程序

Android ProgressBar Shut Down Application

我正在开发初级 android 应用程序。我同时使用 CountDownTimerProgressBar。但是当我为不同的任务使用另一个进度条时应用程序关闭。我什至不能使用 SeekBarProgressBar.

我需要使用另一个 CountDownTimerProgressBar。 当我在 Java.

中调用所需的函数时,应用程序关闭

注意:两种倒计时都没有进度条。

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();
        }

错误:

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.access00(MainActivity.java:32)
        at sengoz.yavuz.MyApp.MainActivity.onClick(MainActivity.java:1079)
        at android.view.View.performClick(View.java:6597)
        at android.view.View.performClickInternal(View.java:6574)
        at android.view.View.access00(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)

您在 seekbar ui 控制器上有一个 nullPointerException。 检查搜索栏是否添加到您在 setContentView(R.layout.<your_layout>)

中设置为参数的相同布局中

使用 onCreate 方法和 xml 代码更新您的代码。