当 XML API 的请求字符串时,我没有得到回复。这是代码:
String url = "http://www.w3schools.com/xml/note.xml"
String url2 = "http://api.json.request"
RequestQueue queue = Volley.newRequestQueue(context);
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String _response) {
Log.d("json=>",_response);
res = _response;
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// Error handling
Log.d("jsone=>", error.toString());
}
});
queue.add(stringRequest);
我使用 Google API(url2)对其进行了测试,但没关系。也许Android Volley在尝试获得响应时运行速度太慢,但看到日志我根本没有得到它。
发起请求时的日志:
01-28 10:57:05.253 21424-21424/com.merahjambutech.zuki.deteksi I/Timeline: Timeline: Activity_launch_request time:26387334
01-28 10:57:05.353 21424-21424/com.merahjambutech.zuki.deteksi D/pre=: 0
01-28 10:57:05.433 21424-21424/com.merahjambutech.zuki.deteksi W/ImageLoader: Try to initialize ImageLoader which had already been initialized before. To re-init ImageLoader with new configuration call ImageLoader.destroy() at first.
01-28 10:57:05.463 21424-21470/com.merahjambutech.zuki.deteksi D/dalvikvm: GC_FOR_ALLOC freed 503K, 11% free 24699K/27632K, paused 29ms, total 29ms
01-28 10:57:05.483 21424-21470/com.merahjambutech.zuki.deteksi I/dalvikvm-heap: Grow heap (frag case) to 29.898MB for 3686416-byte allocation
01-28 10:57:05.543 21424-21424/com.merahjambutech.zuki.deteksi W/ImageLoader: Try to initialize ImageLoader which had already been initialized before. To re-init ImageLoader with new configuration call ImageLoader.destroy() at first.
01-28 10:57:05.573 21424-21547/com.merahjambutech.zuki.deteksi D/dalvikvm: GC_FOR_ALLOC freed 173K, 10% free 28324K/31236K, paused 15ms, total 15ms
01-28 10:57:05.573 21424-21547/com.merahjambutech.zuki.deteksi I/dalvikvm-heap: Grow heap (frag case) to 33.438MB for 3686416-byte allocation </note>
01-28 10:57:05.643 21424-21424/com.merahjambutech.zuki.deteksi I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@42485428 time:26387720
答案 0 :(得分:0)
请确保在manifest
文件中添加权限:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>