0
正在獲取NullPointerException當我單擊父項時。能否請你看看我的代碼爲此提出建議。我沒有得到任何下一步我必須爲這個錯誤採取什麼。試着通過看我的代碼建議我。logcat的屏幕截圖也張貼在這裏。子項ExpandableListView中的NullPointerException
在此先感謝。
public class ExpandListAdapter extends BaseExpandableListAdapter {
private Context context;
private ArrayList<Group> groups;
ImageLoader imageLoader = MyApplication.getInstance().getImageLoader();
public ExpandListAdapter(Context context, ArrayList<Group> groups) {
this.context = context;
this.groups = groups;
}
@Override
public Object getChild(int groupPosition, int childPosition) {
ArrayList<Child> chList = groups.get(groupPosition).getItems();
return chList.get(childPosition);
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
Child child = (Child) getChild(groupPosition, childPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) context
.getSystemService(context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.child_item, null);
}
if (imageLoader == null)
imageLoader = MyApplication.getInstance().getImageLoader();
TextView tv = (TextView) convertView.findViewById(R.id.country_name);
NetworkImageView iv = (NetworkImageView) convertView
.findViewById(R.id.flag);
tv.setText(child.getName().toString());
iv.setImageUrl(String.valueOf(child.getImage()), imageLoader);
return convertView;
}
@Override
public int getChildrenCount(int groupPosition) {
ArrayList<Child> chList = groups.get(groupPosition).getItems();
return chList.size();
}
@Override
public Object getGroup(int groupPosition) {
return groups.get(groupPosition);
}
@Override
public int getGroupCount() {
return groups.size();
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
Group group = (Group) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater inf = (LayoutInflater) context
.getSystemService(context.LAYOUT_INFLATER_SERVICE);
convertView = inf.inflate(R.layout.group_item, null);
}
TextView tv = (TextView) convertView.findViewById(R.id.group_name);
tv.setText(group.getName());
return convertView;
}
@Override
public boolean hasStableIds() {
return true;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
XML文件:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:layout_marginLeft="50dp">
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/flag"
android:layout_marginBottom="14dp"
android:layout_marginLeft="29dp"
android:layout_toRightOf="@+id/flag"
android:text="TextView"
android:textSize="20dp" />
<com.android.volley.toolbox.NetworkImageView
android:id="@+id/flag"
android:layout_width="70dp"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="27dp"
android:src="@drawable/ic_launcher" />
你能不能張貼'child_item'的XML代碼? –
是的,我張貼了,但事情,我不想顯示任何圖像,只是我想顯示一個文本。即使在我的web服務中也沒有圖像 – Mounika12
然後在child_item中爲什麼使用ImageView對象? –