I am trying to get the returned value from a class, however I believe the string.format()
is causing an error resulting in no value to return.
Class:
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;
}
}
When I trace result in my Activity:
FilterTime filterTime = new FilterTime();
String filteredURL = filterTime.getData(dayFilter, timeFilter);
When I trace filteredURL it returns nothing at all. So I then put the Log.d()
into the class and I found that when tracing the following it also returns nothing:
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);
}
I cannot understand where the error is coming from because there are no errors, just a warning saying it should be accessed in a static way, but I think the error resides in the if statement.