我正在尝试从https://github.com/thiagobodruk/bible/blob/master/json/en_kjv.json获取JSONStrings并将它们显示给ListView,但问题是,CPU无法处理该进程并使应用程序崩溃。
en_kjv.json
在AWS S3中,我正在使用Volley获取内容。
齐射代码:
StringRequest requestKJV = new StringRequest(url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
processDone(response, "Genesis");
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MainActivity.this, "Something wen't wrong whilst loading KJV. Please make sure your WiFi/Cellular Data was connected.", Toast.LENGTH_LONG).show();
ArrayList<String> listER = new ArrayList<>();
ArrayAdapter<String> arrayAdapterER = new ArrayAdapter<>(MainActivity.this, R.layout.listview, R.id.items);
}
});
[processDone();
代码:
public void processDone(String mainStringJson, String name) {
ArrayList<String> list= new ArrayList<>();
ArrayAdapter<String> arrayAdapterLP = new ArrayAdapter<>(this, R.layout.listview, R.id.line, list);
try {
JSONArray jsonArray = new JSONArray("[" + mainStringJson + "]");
for(int i=0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
if(jsonObject.getString("name").equals(name)) {
JSONArray chapterArrays = jsonObject.getJSONArray("chapters");
for(int iA=0; iA < chapterArrays.length(); iA++) {
JSONArray jsonArray1 = chapterArrays.getJSONArray(iA);
for(int iB=0; iB < jsonArray1.length(); iB++) {
arrayAdapterLP.add(jsonArray1.getString(iB));
}
}
}
}
} catch (JSONException jsonE){
Toast.makeText(this, "Something wen't wrong. " + jsonE , Toast.LENGTH_LONG).show();
}
lv.setAdapter(arrayAdapterLP);
}
在Logcat中,我得到Task was cancelled
,有时得到Waiting to send non-key event because the touched window has not finished processing certain input events that were delivered to it over 500.0ms ago
。
您是否尝试从https://raw.githubusercontent.com/thiagobodruk/bible/master/json/en_kjv.json获取JSONStrings>
并且您应该使用Retrofit2
,OkHttp而不是StringRequest