当我为Android编写某种HTML下载器时,我决定使用ProgressBar,但它抛出了java.lang.IllegalStateException: The current thread must have a looper!
。我知道这个异常在函数需要在主线程中调用时抛出,但我在runOnUiThread()
中调用它请查看下面的代码。ProgressBar looper异常runOnUiThread
//Inside a worker thread's run()
progressbar.setInterminate(true); //No Exception here
//Connect and get InputStream.
progressbar.setMax(conn.getContentLength()); //No exception here, too
progressbar.setProgress(0); //No exception here.
runOnUiThread(new Runnable() {
@Override
public void run() {
progressbar.setInterminate(false); //Exception here!
}
});
我已经试过移动setProgress()
低于setInterminate(false)
但什么也没做。
在此先感谢。
我假设你的工作线程只运行一次下载的东西?是对的吗? –
@Inferno你是对的。也许我应该使用一个共享的值来存档它? – minary
什么是“进步”?它来自哪里?您似乎有两个不同的进度条对象:'progressbar'和'progress'。请提供更多细节,并可能添加堆栈跟踪。 –