Java 截击请求无法启动请求
当我试图提出请求时,我没有收到任何错误,但它没有提出请求。为了测试它,我添加了一个pritlnJava 截击请求无法启动请求,java,android,json,android-volley,Java,Android,Json,Android Volley,当我试图提出请求时,我没有收到任何错误,但它没有提出请求。为了测试它,我添加了一个pritlnSystem.out.println(“DB每日测试2”)但它不会显示。也许有人会发现我做错了什么 JsonObjectRequest jorDaily = new JsonObjectRequest(Request.Method.GET, "http://api.openweathermap.org/data/2.5/forecast/daily?id=2965140&appid=eacc66
System.out.println(“DB每日测试2”)代码>但它不会显示。也许有人会发现我做错了什么
JsonObjectRequest jorDaily = new JsonObjectRequest(Request.Method.GET, "http://api.openweathermap.org/data/2.5/forecast/daily?id=2965140&appid=eacc664602550623c7fe93a2732ad127" ,null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
ArrayList<WeatherCondition> weatherList = new ArrayList<WeatherCondition>();
System.out.println("DB daily Test 2");
// Trying to extract the imnformation from the JSON response
try {
JSONObject cityObj = response.getJSONObject("city");
JSONObject coordObj = response.getJSONObject("coord");
Coordinates coord = new Coordinates(coordObj.getString("lat"),coordObj.getString("lon"));
JSONArray list = response.getJSONArray("list");
com.example.tadas.betterweather4.City city = new com.example.tadas.betterweather4.City(cityObj.getString("id"),cityObj.getString("name"),cityObj.getString("country"),coord);
System.out.println("DB daily Test 3");
for (int i = 0; i < list.length(); i++) {
String date;
String time;
JSONObject childJSONObject = list.getJSONObject(i);
Calendar calendar = Calendar.getInstance();
calendar.setTimeZone(TimeZone.getDefault());
calendar.setTimeInMillis(childJSONObject.getInt("dt") * 1000);
date = "" + calendar.get(Calendar.YEAR) + "/"+ calendar.get(Calendar.MONTH)+"/"+calendar.get(Calendar.DAY_OF_MONTH);
time = calendar.get(Calendar.HOUR_OF_DAY) + ":00";
JSONObject tempObj = childJSONObject.getJSONObject("temp");
JSONObject weatherObj = childJSONObject.getJSONObject("weather");
Wind wind = new Wind(childJSONObject.getString("deg"), childJSONObject.getString("speed"));
WeatherCondition w = new WeatherCondition(
weatherObj.getString("icon"),
childJSONObject.getString("humidity")+"%",
"",
weatherObj.getString("description"),
"",
childJSONObject.getString("clouds"),
tempObj.getString("temp_main"),
tempObj.getString("temp_max"),
date,
time,
city,
wind
);
w.setCurrent(tempObj.getString("temp"));
weatherList.add(w);
System.out.println("DB daily Test 4");
}
DBHelper db = DBHelper.getInstance(context);
for (WeatherCondition w: weatherList)
{
db.insertDaily(w);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
System.out.println("DB daily Test 00000000000000");
}
}
);
JsonObjectRequest jorDaily=新的JsonObjectRequest(Request.Method.GET,”http://api.openweathermap.org/data/2.5/forecast/daily?id=2965140&appid=eacc664602550623c7fe93a2732ad127“,空,
新的Response.Listener(){
@凌驾
公共void onResponse(JSONObject响应){
ArrayList weatherList=新的ArrayList();
System.out.println(“DB每日测试2”);
//试图从JSON响应中提取信息
试一试{
JSONObject cityObj=response.getJSONObject(“城市”);
JSONObject coordObj=response.getJSONObject(“coord”);
坐标coord=新坐标(coordObj.getString(“lat”)、coordObj.getString(“lon”);
JSONArray list=response.getJSONArray(“list”);
com.example.tadas.betterweather4.City City=new com.example.tadas.betterweather4.City(cityObj.getString(“id”)、cityObj.getString(“名称”)、cityObj.getString(“国家”)、coord);
System.out.println(“DB每日测试3”);
对于(int i=0;i
您只是在创建请求,而不是将其添加到队列中Volley.newRequestQueue(上下文).add(每日)代码>
请记住,拥有RequestQueue的静态实例并将其用于所有请求是一种很好的做法。您只是在创建请求,而不是将其添加到quee中。截击。newRequestQueue(上下文)。添加(jorDaily)谢谢你,错过这个很傻。。。