gpt4 book ai didi

java - 运行App时在Adapter类的getView中获取java.lang.NullPointerException

转载 作者:行者123 更新时间:2023-12-01 22:11:24 25 4
gpt4 key购买 nike

我正在尝试在自定义 ListView 中显示 SQLite 数据库中表中的行,因为我创建了一个 ProductAdapter 类。我在运行应用程序时遇到错误以下是错误

07-31 14:31:42.548    1968-1968/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NullPointerException
at com.sling.freshecomart.ProductAdapter.getView(ProductAdapter.java:54)

以下是行 ProductAdapter.java:54

convertView = mInflater.inflate(R.layout.item,null);

ProductAdapter 类是

public class ProductAdapter extends BaseAdapter {

private LayoutInflater mInflater;
private LayoutInflater inflater=null;

public ProductAdapter(List<Product> list, Activity a) {
this.mProductList = list;
this.activity=a;
inflater = (LayoutInflater) this.activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}


@Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewItem item;

if (convertView == null) {
convertView = mInflater.inflate(R.layout.item,null);

.......

}
}
}

请帮忙并提前致谢

最佳答案

改变

 convertView = mInflater.inflate(R.layout.item,null);

 convertView = inflater.inflate(R.layout.item,null);

因为mInflater=null

关于java - 运行App时在Adapter类的getView中获取java.lang.NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31749003/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com