Handler handler = new Handler() {
public void handleMessage(Message msg) {
super.handleMessage(msg);
ReturnShow.setText(sMsg);//ReturnShow是一个EditText 错误在这里
ReturnShow.setSelection(ReturnShow.length());
}
};
class ReadThread extends Thread {
public void run() {
sMsg = "...";
handler.sendMessage(handler.obtainMessage());
}
}
代码如上, setText那里每次都要出错, 是什么原因? 附上错误信息
RerurnShow为null
ReturnShow = (EditText) findViewById(R.id.ResultShow);这句里面的ID搞错了,弄成一个非当前Activity的ID;
太粗心了
需要在设置ReturnShow
之前对它进行初始化..
比如这样:
ReturnShow = (EditText)findViewById(R.id.edittext);