【发布时间】:2020-03-13 16:48:00
【问题描述】:
我知道有很多类似的线程,但我已经浏览了它们,但仍然无法找出问题所在。我的程序到达 Handler 但它总是返回 catch 异常“消息未处理。”
我声明了 TextView private TextView chatbox;
在 onCreate 下我有:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setUpViews();
setUpListener();
}
setUpViews() sn-p 的样子:
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 文件中的片段:
<TextView
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" />
【问题讨论】:
-
你遇到了什么异常?