2
저는 JSON과 asynctask를 사용하기 위해 mysql에서 데이터를 검색하는 expandablelistview를 가지고 있습니다. asynctask 클래스는 주 활동 클래스에도 있습니다. 프로그램을 실행할 때이 오류가 발생했습니다. 시도는 onPostExecute에서 하나에서 System.out.println 때활동을 시작할 수 없습니다 ComponentInfo ExpandableListview
이new ProsesTampil().execute(url);
exProteinAdapter = new com.ta.helper.ExpandableListAdapterKonsumsi(
this, listDataHeaderProtein, listDataChildProtein);
exProtein.setAdapter(exProteinAdapter);
exProtein.setOnChildClickListener(new OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
group = groupPosition;
child = childPosition;
String kaloriString = listTakaranKaloriChildProtein.get(
listDataHeaderProtein.get(groupPosition)).get(
childPosition);
kalori = Float.parseFloat(kaloriString);
kolomKalori.setText("" + kalori);
String namaMakanan = listDataChildProtein.get(
listDataHeaderProtein.get(groupPosition)).get(
childPosition);
kolomNamaMakanan.setText(namaMakanan);
return true;
}
});
class ProsesTampil extends AsyncTask<String, Void, JSONObject> {
@Override
protected JSONObject doInBackground(String... params) {
return JSONfunctions.getJSONfromURL(params[0]);
}
@Override
protected void onPostExecute(JSONObject result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
exProtein = (ExpandableListView) findViewById(R.id.EVprotein);
exProtein.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
listDataHeaderProtein = new ArrayList<String>();
Collections.addAll(listDataHeaderProtein, getResources()
.getStringArray(R.array.input_menuP));
List<String> daftarMakanan = new ArrayList<String>();
List<String> takaranKaloriDaftarMakanan = new ArrayList<String>();
//System.out.println(result);
try {
JSONArray makanan = result.getJSONArray("food");
for (int i = 0; i < makanan.length(); i++) {
// nama
Collections.addAll(daftarMakanan, makanan.getJSONObject(i)
.getString("nama_makanan").toString());
listDataChildProtein = new HashMap<String, List<String>>();
listDataChildProtein.put(listDataHeaderProtein.get(0),
daftarMakanan);
System.out.println(listDataChildProtein);
// kalori
Collections.addAll(takaranKaloriDaftarMakanan, makanan
.getJSONObject(i).getString("energi"));
listTakaranKaloriChildProtein = new HashMap<String, List<String>>();
listTakaranKaloriChildProtein.put(listDataHeaderProtein.get(0),
takaranKaloriDaftarMakanan);
System.out.println(listTakaranKaloriChildProtein);
}
} catch (JSONException e) {
Log.e("log_tag", "Error parsing data " + e.toString());
}
}
어댑터 클래스
public ExpandableListAdapterKonsumsi(Context context,
List<String> listDataHeader,
HashMap<String, List<String>> listDataChild) {
super();
this.context = context;
this.listDataHeader = listDataHeader;
this.listDataChild = listDataChild;
}
@Override
public Object getChild(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return this.listDataChild.get(this.listDataHeader.get(groupPosition))
.get(childPosition);
}
@Override
public long getChildId(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return childPosition;
}
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
final String childText = (String) getChild(groupPosition, childPosition);
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) this.context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(
R.layout.konsumsi_user_expand_listchild, null);
}
CheckedTextView listChild = (CheckedTextView) convertView
.findViewById(R.id.lblListItemKonsumsi);
listChild.setText(childText);
return convertView;
}
@Override
public int getChildrenCount(int groupPosition) {
// TODO Auto-generated method stub
return this.listDataChild.get(this.listDataHeader.get(groupPosition))
.size();
}
@Override
public Object getGroup(int groupPosition) {
// TODO Auto-generated method stub
return this.listDataHeader.get(groupPosition);
}
@Override
public int getGroupCount() {
// TODO Auto-generated method stub
return this.listDataHeader.size();
}
@Override
public long getGroupId(int groupPosition) {
// TODO Auto-generated method stub
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
String headerTitle = (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this.context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(
R.layout.daftar_akun_expand_listgroup, null);
}
TextView lblListHeader = (TextView) convertView
.findViewById(R.id.lblListHeader);
lblListHeader.setTypeface(null, Typeface.BOLD);
lblListHeader.setText(headerTitle);
return convertView;
}
@Override
public boolean hasStableIds() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return true;
}
}
그것은 올바른 데이터를 검색하지만, 메인 프로그램을 보인다
여기 내 주요 클래스의 그것을 인식 할 수 없습니다 (null).
미리 감사드립니다.