在 Adapter class 的 getView 中获取 java.lang.NullPointerException 而在 App 运行 中获取 java.lang.NullPointerException
Getting java.lang.NullPointerException in getView of Adapter class while running the App
我正在尝试在自定义 ListView 的 SQLite 数据库中显示我的 table 中的行,为此我创建了一个 ProductAdapter class。
运行 应用程序时出现错误
以下是错误
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 class 是
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
我正在尝试在自定义 ListView 的 SQLite 数据库中显示我的 table 中的行,为此我创建了一个 ProductAdapter class。 运行 应用程序时出现错误 以下是错误
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 class 是
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