1
getDataを呼び出すと、onResponseから結果を取得するのが難しいようです。私はそれが現在のこの方法ではうまくいかないことを知っています。誰も私がこの問題を解決するのを手伝ってもらえますか?Volley JSON onResponse関数を実行しない
のgetData()
private void getData(){
//Creating a string request
StringRequest stringRequest = new StringRequest(SPINNER_URL, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
// Log.d("Country_name","hi");
JSONObject j = null;
try {
//Parsing the fetched Json String to JSON Object
j = new JSONObject(response);
//Storing the Array of JSON String to our JSON Array
result = j.getJSONArray(JSON_ARRAY);
Log.v("xxxxx",result.toString());
String mysh=result.toString().substring(1, result.toString().length()-1);
JSONArray jsonArray = new JSONArray(mysh);
//Calling method getCountry to get the country from the JSON Array
getCountry(jsonArray);
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
//Creating a request queue
RequestQueue requestQueue = Volley.newRequestQueue(this);
//Adding request to the queue
requestQueue.add(stringRequest);
}
を動作するはずだと思うこれを試してみてください。あなたはjson応答を追加できますか? – W4R10CK
onErrorResponse()はどうですか?何らかのエラーのために呼ばれていないのですか? – abbath
StringRequestの代わりにjsonRequestを実行した方が簡単でしょうか?また、試しにすべてのものがキャッチされているのはなぜですか?応答が良い場合は、必要はありません、右か? –