전설의 리그에서 모든 챔피언 ID가있는 JSON 개체를 가져 오는 방법이 있습니다. 프로그램의 다른 루프에서 메서드에 전달되는 "숫자"를 기반으로 챔피언의 이름을 반환합니다.내 메서드는 문자열을 반환해야하지만 내 메서드는 문자열을 반환하는 return 문을 가지고 있다고 계속 말합니다.
public String getChampionName(int number) //where it is saying its not returning a string
{
try
{
String JSonChampionName = readURL("myURLwithAPIkey");
JSONObject object = JSONObject.fromObject(JSonChampionName);
JSONObject championData = (JSONObject)(object.get("data"));
JSONObject champName = (JSONObject)(championData.get(number));
if(object != null && championData != null && champName != null)
{
String cName = champName.get("name").toString();
return cName;
}
else
return "";
}catch(Exception v){}
}
어떤 아이디어라도 그 방법이 문자열을 반환하지 않는 이유는 확실하지 않습니다.
예외가 throw 된 경우이 메서드는 어떻게됩니까? 그러면 문자열이 반환되지 않습니다. 그것이 그 불평 이유입니다. –
예외가 발생하여 잡으면 ... 정확히 무엇을 반환합니까? –
[Java 기본 - 가능한 반환 유형 및 메서드에서 return 문 약간의 혼란] 가능한 중복 (http://stackoverflow.com/questions/8287717/java-fundamental-a-little-confusion-on-return-type-and -return-statement-in-met) –