【发布时间】:2015-12-05 13:23:39
【问题描述】:
所以我正在使用以下适配器制作一个可扩展的 listView:
class SubcategoriesAdapter extends BaseExpandableListAdapter {
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
View v=convertView;
if(v==null) v=layoutInflater.inflate(R.layout.tip_view, null, false);
((TextView)v.findViewById(R.id.title)).setText(data.subcategories.get(groupPosition).tips.get(childPosition).title);
((TextView)v.findViewById(R.id.content)).setText(data.subcategories.get(groupPosition).tips.get(childPosition).text);
return v;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
@Override
public int getGroupCount() {
return data.subcategories.size();
}
@Override
public int getChildrenCount(int groupPosition) {
return data.subcategories.get(groupPosition).tips.size();
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return data.subcategories.get(groupPosition).tips.get(childPosition);
}
@Override
public long getGroupId(int groupPosition) {
return 0;
}
@Override
public Object getGroup(int groupPosition) {
return data.subcategories.get(groupPosition);
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return 0;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
View v=convertView;
Tips.TipsSubcategory me=data.subcategories.get(groupPosition);
if(v==null) v=LayoutInflater.from(getContext()).inflate(R.layout.tips_subcategory_view, null, false);
/* ((TextView)v.findViewById(R.id.title)).setText(me.title);
Picasso.with(getActivity()).load(me.ad_url).into(((ImageView) v.findViewById(R.id.adImageView)));
Picasso.with(getActivity()).load(me.image_url).into((ImageView)v.findViewById(R.id.image)); */
return v;
}
}
当我加载包含列表的 Fragment 时,出现以下异常:
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:715)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at biz.energit.cookingfridge.user.fragments.TipsCategory$SubcategoriesAdapter.getGroupView(TipsCategory.java:148)
它指向的这条线,148 是我膨胀视图的线:
if(v==null) v=LayoutInflater.from(getContext()).inflate(R.layout.tips_subcategory_view, null, false);
我尝试删除i,传递实际的父代而不是null,并从片段或通过其他方式获取充气器。我一无所知。
更新:以防万一有人再次遇到此问题,我无法写答案,因为有人将其标记为重复。
问题是在我膨胀的 XML 中使用 <view 而不是 <View。编译器对此只字未提,但问题本身就是这样。
【问题讨论】:
-
This is the evil line。您应该使用调试器来了解为什么
attrs.getAttributeValue(null, "class");返回null。
标签: java android expandablelistview expandablelistadapter