Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/192.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 正在尝试从API获取数据_Java_Android_Json_Api_Android Volley - Fatal编程技术网

Java 正在尝试从API获取数据

Java 正在尝试从API获取数据,java,android,json,api,android-volley,Java,Android,Json,Api,Android Volley,我目前正在开发一个android应用程序,它可以通过ASP.NET Restful Web API显示天气信息。我编写了一个方法,该方法接收城市名称,获取天气信息并将其发送到MainActivity,然后将其显示在屏幕上,但出于某种原因,它会显示catch异常消息。我试着看logcat寻找答案,但什么也没有出来 如有任何帮助,将不胜感激: 用于从api获取数据的方法 公共接口WeatherByCity响应{ void onError(字符串消息); 无效响应(天气信息天气信息); } 公共无效g

我目前正在开发一个android应用程序,它可以通过ASP.NET Restful Web API显示天气信息。我编写了一个方法,该方法接收城市名称,获取天气信息并将其发送到MainActivity,然后将其显示在屏幕上,但出于某种原因,它会显示catch异常消息。我试着看logcat寻找答案,但什么也没有出来

如有任何帮助,将不胜感激:

用于从api获取数据的方法

公共接口WeatherByCity响应{
void onError(字符串消息);
无效响应(天气信息天气信息);
}
公共无效getWeatherByCity(字符串城市,最终WeatherByCity响应WeatherByCity响应){
列表报告=新的ArrayList();
字符串url=查询+城市;
JsonArrayRequest=newJSONArrayRequest(request.Method.GET,url,null,new Response.Listener()){
@凌驾
公共void onResponse(JSONArray响应){
试一试{
WeatherInformation weather=新的WeatherInformation();
JSONObject weatherInfo=response.getJSONObject(0);
weather.setId(weatherInfo.getInt(“id”));
weather.setCity(weatherInfo.getString(“city”);
weather.setConditions(weatherInfo.getString(“condition”);
weather.setMinTemp(weatherInfo.getInt(“minTemperature”);
weather.setMaxTemp(weatherInfo.getInt(“maxTemperature”);
weather.setWindDirect(weatherInfo.getString(“windDirection”);
weather.setWindSpeed(weatherInfo.getInt(“windSpeed”);
weather.setOutlook(weatherInfo.getString(“outlook”);
WeatherByCity响应响应(天气);
}捕获(JSONException e){
e、 printStackTrace();
}
}
},new Response.ErrorListener(){
@凌驾
公共无效onErrorResponse(截击错误){
Toast.makeText(上下文“ooga booga”,Toast.LENGTH_SHORT).show();
}
});
getInstance(上下文).addToRequestQueue(请求);
}

可能尝试打印一些有关您收到的错误的相关信息,而不是伪字符串?实际的异常消息是什么?