首页 > 代码库 > 遇到java.lang.IllegalThreadStateException: Thread already started. 错误的解决办法

遇到java.lang.IllegalThreadStateException: Thread already started. 错误的解决办法

通过单击事件开启线程时,再次单击就会出现 java.lang.IllegalThreadStateException: Thread already started. 错误

解决办法:

创建一个Runnable:

Runnable DownloadRunnable = new Runnable() {

@Override
public void run() {

   //需要处理操作
}

然后每次需要调用的时候会重新new一个Thread:
new Thread(DownloadRunnable).start();