调试安卓BaseAdapter中的inflater的时候总是会跳出这个错误,我明明给inflater赋了值的
代码:publicViewgetView(intposition,ViewconvertView,ViewGroupparent){Viewv;if(convertVie...
代码:
public View getView(int position, View convertView, ViewGroup parent) {
View v;
if(convertView==null){
v=inflater.inflate(R.layout.item, null);
}else{
v=convertView;
}
TextView tv = (TextView) v.findViewById(R.id.tv);
tv.setText("position"+position);
return v;
}
错误:
java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup)' on a null object reference
inflater是初始化过的:LayoutInflater inflater; 展开
public View getView(int position, View convertView, ViewGroup parent) {
View v;
if(convertView==null){
v=inflater.inflate(R.layout.item, null);
}else{
v=convertView;
}
TextView tv = (TextView) v.findViewById(R.id.tv);
tv.setText("position"+position);
return v;
}
错误:
java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup)' on a null object reference
inflater是初始化过的:LayoutInflater inflater; 展开
2个回答
展开全部
这样LayoutInflater inflater肯定为空,你这叫声明不叫初始化,
这样:LayoutInflater inflater= LayoutInflater.from(context);才行
这样:LayoutInflater inflater= LayoutInflater.from(context);才行
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询