我在一个客户端页面的构造方法中创建了一个线程,用来监听Socket的inputStream,并从中取值更新到displayArea中:
new Thread (new Runnable(){
public void run(){
String line;
try {
while(true){
line = is.readLine();
System.out.println("read a time;");
synchronized(displayArea){
displayArea.append(line);
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
运行报线程非法访问异常:Invalid thread access
在swt中不能用这种方法创建线程吗?
new Thread (new Runnable(){
public void run(){
String line;
try {
while(true){
line = is.readLine();
System.out.println("read a time;");
synchronized(displayArea){
displayArea.append(line);
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
运行报线程非法访问异常:Invalid thread access
在swt中不能用这种方法创建线程吗?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货