“while”语句如果不引发异常就无法完成 - Android
2022-09-03 03:12:10
使用这种方法,我每秒都会更新一次。TextView
private void UpdatingTime(final String endTime, final long diffInDays) {
new Thread(new Runnable() {
@Override
public void run() {
while (true) {
try {
Thread.sleep(ONE_SECOND);
mHandler.post(new Runnable() {
@Override
public void run() {
// Updating time every second
long diffInHours = Methodes.diffInHours(endTime, diffInDays);
long diffInMinutes = Methodes.diffInMinutes(endTime, diffInDays, diffInHours);
long diffInSeconds = Methodes.diffInSeconds(endTime, diffInDays, diffInHours, diffInMinutes);
tvTime2.setText(addZeroInFront(diffInHours)
+ ":" + addZeroInFront(diffInMinutes)
+ ":" + addZeroInFront(diffInSeconds));
}
private String addZeroInFront(long diffInHours) {
String s = "" + diffInHours;
if (s.length() == 1) {
String temp = s;
s = "0" + temp;
}
return s;
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
}
}).start();
}
}
这种方法非常完美。但是我得到了这个警告:
“while”语句如果不引发异常,就无法完成。
报告只能通过引发异常退出的语句、while 语句或 do 语句。虽然这些陈述可能是正确的,但它们通常是编码错误的症状。
我讨厌警告,我想修复它。我该如何修复此警告,或者有更好的解决方案来解决这个问题?