我正在尝试从一个类中获取返回值,但是我相信这string.format()
会导致错误导致没有返回值。
班级:
public class FilterTime {
public String getData(String day, Integer time){
// define the result
String result = "";
String convertedDay = "";
if(day == "Friday 30th August"){
convertedDay = "30";
}
if(day == "Saturday 31st August"){
convertedDay = "31";
}
if(day == "Sunday 1st September"){
convertedDay = "01";
}
if(time == null){
result = "http://www.website.org/json.php?f=%s&type=date".format(convertedDay);
Log.d("RESULT", "r:" + result);
}else{
result = "http://www.website.org/json.php?f=%s&time=@d&type=dateAndTime".format(convertedDay, time);
Log.d("RESULT", "r:" + result);
}
return result;
}
}
当我在我的活动中跟踪结果时:
FilterTime filterTime = new FilterTime();
String filteredURL = filterTime.getData(dayFilter, timeFilter);
当我跟踪filteredURL时,它根本不返回任何内容。所以我然后将其Log.d()
放入类中,我发现在跟踪以下内容时它也没有返回任何内容:
if(time == null){
result = "http://www.website.org/json.php?f=%s&type=date".format(convertedDay);
Log.d("RESULT", "r:" + result);
}else{
result = "http://www.website.org/json.php?f=%s&time=@d&type=dateAndTime".format(convertedDay, time);
Log.d("RESULT", "r:" + result);
}
我不明白错误来自哪里,因为没有错误,只是警告说应该以静态方式访问它,但我认为错误存在于 if 语句中。