Yahoo Weather API를 기반으로 기본 Get Request를 실행 중입니다. 그것은 유튜브에서 예제입니다 .. 나는 그것을 실행할 수 없습니다 .. 내 HTTP 요청에 doInBackground 메서드에서 런타임 오류가 발생합니다. (아래 참조).HTTP Get Request - Incompatible Types
내 전화기에서 "Value True of Type Java.lang.boolean을 JSON 개체로 변환 할 수 없습니다."라는 오류 메시지가 나타납니다. 그래서 String을 반환해야합니다. 하지만 "라인"유형을 String으로 변경하면 "호환되지 않는 유형 - 필수 java.lang.String - found Boolean"오류가 발생합니다. 그래서 BufferedReader의 readline 명령은 String을 기대하지만 Boolean을 찾습니다. 아무도 나에게 어떤 일이 일어나고 어떻게 해결할 수 있습니까?
미리 감사드립니다.
공공 무효 refreshWeather (최종 문자열 위치) {
new AsyncTask<String, Void, String>()
{
@Override
protected String doInBackground(String... strings) {
String YQL = String.format("select * from weather.forecast where woeid in (select woeid from geo.places(1) where text=\"%s\")",location);
String endpoint = String.format("https://query.yahooapis.com/v1/public/yql?q=%s&format=json", Uri.encode(YQL));
try {
URL url = new URL(endpoint);
URLConnection connection = url.openConnection();
InputStream inputStream = connection.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
StringBuilder result = new StringBuilder();
boolean line;
while ((line = reader.readLine()!= null)){
result.append(line);
}
return result.toString();
} catch (Exception e) {
error = e;
}
return null;
}
/**
onPostExecute checks first if there is a service failure, then if city is valid, then it
populates the data from the city and goes to method serviceSuccess and populates the fields with the retrieved data
*/
@Override
protected void onPostExecute(String s) {
if (s == null && error != null){
callback.serviceFailure(error);
return;
}
try {
JSONObject data = new JSONObject(s);
JSONObject queryResults = data.optJSONObject("query");
int count = queryResults.optInt("count");
if (count == 0){
callback.serviceFailure(new LocationWeatherException("No Weather Info Found for" + location));
return;
}
Channel channel = new Channel();
channel.populate(queryResults.optJSONObject("results").optJSONObject("channel"));
callback.serviceSuccess(channel);
} catch (JSONException e) {
callback.serviceFailure(e);
}
}
}.execute(location);
}
당신이 어떤 라인에 이러한 오류가 발생할 로그 캣에서 확인하실 수 있습니다 : 당신이 그것을 호출하기 전에
는line != null
예를 사용하여 변수를 설정하려고? – tobifasc