似たようなスレッドがたくさんあることは知っていますが、それらを調べてもまだ問題がわかりません。私のプログラムはハンドラーに到達しますが、常にキャッチ例外「メッセージが処理されていません」を返します。
TextView を宣言しましたprivate TextView chatbox;
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 ファイルのスニペット:
<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" />