我得到这个错误:的IsAlive problem..Help了解它是如何工作
"non-static method isAlive() cannot be referenced from a static context"
什么不对的code..please。
我想检测是否该线程是活着... 中的代码会方面的任何帮助,高度appreciated..thanks 最大
class RecThread extends Thread { public void run() { recFile = new File("recorded_track.wav"); // Output file type AudioFileFormat.Type fileType = null; fileType = AudioFileFormat.Type.WAVE; // if rcOn =1 thread is alive int rcOn; try { // starts recording targetDataLine.open(audioFormat); targetDataLine.start(); AudioSystem.write(new AudioInputStream(targetDataLine), fileType, recFile); if (RecThread.isAlive() == true) { rcOn =1; } else { rcOn =0; } } catch (Exception e) { showException(e); } // update actions recAction.setEnabled(true); stopRecAction.setEnabled(false); } }
扩展线程通常不是这样一个好主意,请尝试使用Runnable。请使用rcOn的布尔变量。 – Thilo 2011-01-12 09:21:54
* if(boolean == true)*不是很好阅读。人们往往更喜欢简单:* if(布尔值)* – Gugussee 2011-01-12 10:07:22