我正在创建一个 Android Studios 任务列表应用程序。由于某种原因,即使表达式为假,也会调用 IF 语句,从而在运行时产生错误。代码如下:
if (taskArray5.get(0).equals( "Goal Time Not Specified") ) {
Log.d("hello", taskArray5.get(0).getClass().toString());
Log.d("hello", taskArray5.get(0));
String[] localTimeList = localTime.split(":");
String previouslySetTime = taskArray5.get(0).substring(0, taskArray5.get(0).length() - 5);
String[] previouslySetTimeList = previouslySetTime.split(":");
Integer localTimeHours = Integer.parseInt(localTimeList[0]);
Integer localTimeMinutes = Integer.parseInt(localTimeList[1]);
Integer localTimeSeconds = Integer.parseInt(localTimeList[2]);
char AMORPM = taskArray5.get(0).charAt(taskArray5.get(0).length() - 4);
Integer previouslySetTimeHours;
if (AMORPM == 'A') {
previouslySetTimeHours = Integer.parseInt(previouslySetTimeList[0]);
} else {
previouslySetTimeHours = Integer.parseInt(previouslySetTimeList[0]) + 12;
}
我使用 Log.d 确认 taskArray5.get(0) 是一个具有特定值“目标时间未指定”的字符串。另外,使用equals()函数也没有解决问题。我究竟做错了什么?任何帮助表示赞赏。
温温酱
相关分类