好的,我现在遇到了一个很大的问题,我在尝试从我的子视图中获取数据时遇到了一个nullpointer异常
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
ViewHolder holder = null;
View vi = convertView;
final commentSubItem item = getChild(groupPosition, childPosition);
System.out.println(item.user_img);
item.user_img正在发出一个nullpointer异常。
class commentItem{
int is_load_more = 0, position, last_time;
public String user_id, user_fullname, user_username, user_img, comment_data, comment_bumps, total_replies, post_id, comment_id, isBumped;
public List<commentSubItem> subComments = new ArrayList<commentSubItem>();
public commentItem(int ism, int lt){
is_load_more = ism;
last_time = lt;
}
public commentItem(String uid, String ufn, String uun, String uim, String pd, String pb, String tr, String pid, String cid, String isB){
user_id = uid;
user_fullname = ufn;
user_username = uun;
user_img = uim;
comment_data = pd;
comment_bumps = pb;
total_replies = tr;
post_id = pid;
comment_id = cid;
isBumped = isB;
}
}
class commentSubItem{
int is_load_more = 0, position, last_time;
public String user_id, user_fullname, user_username, user_img, comment_data, comment_bumps, total_replies, post_id, comment_id, isBumped;
public commentSubItem(int ism, int lt){
is_load_more = ism;
last_time = lt;
}
public commentSubItem(String uid, String ufn, String uun, String uim, String pd, String pb, String tr, String pid, String cid, String isB){
user_id = uid;
user_fullname = ufn;
user_username = uun;
user_img = uim;
comment_data = pd;
comment_bumps = pb;
total_replies = tr;
post_id = pid;
comment_id = cid;
isBumped = isB;
}
}
public commentSubItem getChild(int groupPosition, int childPosition) {
return comments.get(groupPosition).subComments.get(childPosition);
}
我正在填写arraylist:
publishProgress(new commentSubItem(commenterData.getString("user_id"),
commenterData.getString("user_fullname"),
commenterData.getString("user_username"),
commenterData.getString("user_img"),
commentData.getString("comment_data"),
commentData.getString("comment_bumps"),
main.getString("comment_total"),
post_id.toString(),
commentData.getString("comment_id"),
isBumped));
@Override
protected void onProgressUpdate(commentSubItem... pI) {
super.onProgressUpdate();
adapter.addAdapterSubItem(group_id, pI[0]);
public void addAdapterSubItem(int itx, commentSubItem item) {
comments.get(itx).subComments.add(item);
}
现在我无法弄清楚为什么getChildView为null,因为commenterData.getString(“user_img”)给出了一个值。任何人都可以帮助我吗?
编辑:当我将groupPosition传递给它时,group_id是正确的值
答案 0 :(得分:0)
出于某种原因使用comments.get(itx).subcomments.add(item)等没有工作我最终在comments类中添加了add子命令函数,然后从addadaptersubitem调用它们等。工作正常没有更多的空指针异常
class commentItem{
int is_load_more = 0, position, last_time;
public String user_id, user_fullname, user_username, user_img, comment_data, comment_bumps, total_replies, post_id, comment_id, isBumped;
public List<commentSubItem> subComments = new ArrayList<commentSubItem>();
public commentItem(int ism, int lt){
is_load_more = ism;
last_time = lt;
}
public commentItem(String uid, String ufn, String uun, String uim, String pd, String pb, String tr, String pid, String cid, String isB){
user_id = uid;
user_fullname = ufn;
user_username = uun;
user_img = uim;
comment_data = pd;
comment_bumps = pb;
total_replies = tr;
post_id = pid;
comment_id = cid;
isBumped = isB;
}
public void addSubComment(commentSubItem e){
subComments.add(e);
}
public void addSubComment(int index, commentSubItem e){
subComments.add(index, e);
}
public void removeSubComment(commentSubItem e){
subComments.remove(e);
}
public void removeSubComment(int e){
subComments.remove(e);
}
public commentSubItem getSubComment(int e){
return subComments.get(e);
}
}
然后我只是调用这样的函数:
public commentSubItem getChild(int groupPosition, int childPosition) {
return comments.get(groupPosition).getSubComment(childPosition);
}