我知道有很多类似的线程,但我已经完成了它们仍然无法弄清楚问题.我的程序到达处理程序,但它总是返回捕获异常“消息未处理”.
我声明了TextView私有TextView聊天框;
在onCreate下我有:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setUpViews();
setUpListener();
}
其中setUpViews()片段如下所示:
private void setUpViews() {
chatbox = (TextView) findViewById(R.id.chatbox);
}
处理器:
public Handler mHandler = new Handler(Looper.getMainLooper()){
@Override
public void handleMessage(Message msg){
try{
chatbox.setText("Got it!");
}catch(Exception e){
Log.i("MYLOG", "Message was not handled.");
}
}
};
main.xml文件中的代码段:
android:id="@+id/chatbox"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textAppearance="?android:attr/textAppearanceLarge" />