class MyRunnable implements Runnable{
public StringBuffer line2;
public MyRunnable(StringBuffer _line){
this.line2 = _line;
Log.w("LINE", this.line2.toString()); // Return what it should
}
public void run(){
console.append(this.line2.toString()); //Nothing happens here
}
}
这是我的代码。我有一个问题,当从run()
方法访问 line2 时,它的长度为 0。
编辑:这是我的电话
new Thread(new Runnable() {
@Override
public void run() {
StringBuffer line = new StringBuffer();
while(true){
char a = UART.serialRead(UART.fd);
if(a != 0){
if (a == '\r' || a == '\n'){
MyRunnable obj = new MyRunnable(line);
handler.post(obj);
line.delete(0, line.length());
obj = null;
}else
line.append(a);
}
try {
Thread.sleep(50);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}).start();
知道我哪里错了吗?