text.setText(hourOfDay); // hourOfDay 為 int
// logcat: Exception dispatching input event / Resources$NotFoundException
TextView.setText(int) 會嘗試將參數視為字串資源 ID(R.string.xxx),找不到對應資源則拋出 Resources$NotFoundException。
text.setText(Integer.toString(hourOfDay));
// 或
text.setText(String.valueOf(hourOfDay));
// 或
text.setText(hourOfDay + "");
將整數明確轉為 String 呼叫 setText(CharSequence) 多載。
View.setText(int) 均視為資源 ID,若需顯示數值,必須先轉字串。text.text = hourOfDay.toString() 同理。String.format 可同時格式化:text.setText(String.format("%02d:%02d", hour, min))。