我想通过从JSON检索数据来创建列表项,但它失败了,日志聊天是:
无法找到从方法'android.graphics.drawable.RippleDrawable'
引用的课程android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering
解析数据org.json.JSONException
时出错:title`
这是我的JSON:
{
"berita": [
{
"id_berita": "1",
"judul_berita": "abcdefgh",
"gambar_berita": "media.jpg",
"isi_berita": "arsgrdgrdgrdgrfdrffffffffffrvfsffsfsfsf"
},
{
"id_berita": "2",
"judul_berita": "ijklmnopqrst",
"gambar_berita": "back.jpg",
"isi_berita": "kbkjcbkjbcjkbckjanckjnakjcbjkabcjkabcjabcjhbcjdbcjdb"
}
]
这是我的代码
protected Void doInBackground(Void... voids) {
HttpHandler sh = new HttpHandler();
String jsonStr = sh.makeServiceCall(url);
Log.e(TAG, "Response from url : "+jsonStr);
if(jsonStr != null){
try{
JSONObject jsonObject = new JSONObject(jsonStr);
//getting node json array
JSONArray berita = jsonObject.getJSONArray("berita");
//looping semua berita
for(int i = 0; i < berita.length(); i++){
JSONObject c = berita.getJSONObject(i);
String id_berita = c.getString("id_berita");
String judul_berita = c.getString("judul_berita");
HashMap<String, String> Berita = new HashMap<>();
Berita.put("id_berita", id_berita);
Berita.put("judul_berita", judul_berita);
}
}
catch (final JSONException e){
Log.e(TAG, "JSON parsing error : "+e.getMessage());
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(BeritaActivity.this, "JSON parsing error"+e.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
}else {
Log.e(TAG, "Tidak bisa mendapat JSON dari server");
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(BeritaActivity.this, "Tidak bisa mendapat JSON dari server", Toast.LENGTH_SHORT).show();
}
});
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
if(pDialog.isShowing()){
pDialog.dismiss();
}
ListAdapter adapter = new SimpleAdapter(
BeritaActivity.this, beritaList,
R.layout.list_item, new String[]{"judul_berita"},
new int[]{R.id.judulBerita});
lv.setAdapter(adapter);
}
}