所以我有这个小问题我无法处理...检查代码并阅读Logcat,任何想法?
CODE:
for(int i = 0; i < jArray.length(); ++i){
JSONObject json_data = jArray.getJSONObject(i);
//
String paskaita = json_data.getString("paskaita");
String laikas = json_data.getString("laikas");
String savaite = json_data.getString("savaite");
String auditorija = json_data.getString("auditorija");
String destytojas = json_data.getString("destytojas");
String dalykas = json_data.getString("dalykas");
String tipas = json_data.getString("tipas");
//Just adding view
TextView pask = (TextView) Item.findViewById(R.id.paskaita);
pask.setText(paskaita);
TextView laik = (TextView) Item.findViewById(R.id.laikas);
laik.setText(laikas);
TextView sav = (TextView) Item.findViewById(R.id.savaite);
sav.setText(savaite);
TextView dest = (TextView) Item.findViewById(R.id.destytojas);
dest.setText(destytojas);
TextView aud = (TextView) Item.findViewById(R.id.auditorija);
aud.setText(auditorija);
TextView dal = (TextView) Item.findViewById(R.id.dalykas);
dal.setText(dalykas);
TextView tip = (TextView) Item.findViewById(R.id.tipas);
tip.setText(tipas);
ln.addView(Item);
}
Logcat输出:
12-07 19:00:27.558: E/AndroidRuntime(280): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
答案 0 :(得分:1)
好的,它与你的JSONObject无关。
Logcat说明了一切。您添加已有父级的TextView。所以你可能想要创建一个布局,并在你的for循环中
for(int i = 0; i < jArray.length(); ++i){
JSONObject json_data = jArray.getJSONObject(i);
//
String paskaita = json_data.getString("paskaita");
String laikas = json_data.getString("laikas");
String savaite = json_data.getString("savaite");
String auditorija = json_data.getString("auditorija");
String destytojas = json_data.getString("destytojas");
String dalykas = json_data.getString("dalykas");
String tipas = json_data.getString("tipas");
// Create a new view every time.
View Item = View.inflate(ln.getContext(), layoutID, null);
//Just adding view
TextView pask = (TextView) Item.findViewById(R.id.paskaita);
pask.setText(paskaita);
TextView laik = (TextView) Item.findViewById(R.id.laikas);
laik.setText(laikas);
TextView sav = (TextView) Item.findViewById(R.id.savaite);
sav.setText(savaite);
TextView dest = (TextView) Item.findViewById(R.id.destytojas);
dest.setText(destytojas);
TextView aud = (TextView) Item.findViewById(R.id.auditorija);
aud.setText(auditorija);
TextView dal = (TextView) Item.findViewById(R.id.dalykas);
dal.setText(dalykas);
TextView tip = (TextView) Item.findViewById(R.id.tipas);
tip.setText(tipas);
ln.addView(Item);
}