android - Android ProgressBar 关闭应用程序
问题描述
我正在开发一个初学者级别的 android 应用程序。我正在使用CountDownTimer
和ProgressBar
在一起。但是当我将另一个进度条用于不同的任务时,应用程序会关闭。我什至不能使用SeekBar
or 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();
}
错误:
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)
解决方案
你有一个nullPointerException
uiseekbar
控制器。检查是否在您设置为参数的相同布局中添加了搜索栏setContentView(R.layout.<your_layout>)
使用 onCreate 方法和 xml 代码更新您的代码。
推荐阅读
- java - 如何拥有多个spring boot批处理配置类
- jquery - jquery .offset().top 没有预期的行为
- centos - 无法在 CentOS 8 上安装 Icinga Web 2
- python - 在 Python 中创建具有序号的矩阵
- facebook - 如何在网站上显示 Facebook 页面约会
- java - cucumber.runtime.junit.UndefinedThrowable:步骤未定义
- java - 发现在tomcat生成端口(动态端口)之前向端口0注册服务
- php - 如果条件,如何在 jQuery 中取消设置 PHP 会话变量?
- python - django如何制作自定义网址
- python - 散景在循环中绘制多个图像