我正在开发初学者级别的android应用程序。我正在同时使用CountDownTimer
和ProgressBar
。但是,当我将另一个进度栏用于其他任务时,应用程序将关闭。我什至不能使用SeekBar
或ProgressBar
。
我需要将另一个CountDownTimer
与ProgressBar
一起使用。
当我在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();
}
Errrr:
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)
答案 0 :(得分:1)
您在nullPointerException
的ui控制器上有一个seekbar
。
检查是否在与setContentView(R.layout.<your_layout>)
使用onCreate方法和xml代码更新您的代码。