我正在使用应用ListView
显示一些数据的应用程序。一切正常,但是当我按下“后退”按钮时,我的应用程序崩溃了,我得到NullPointer Exception
。这是我的基本适配器:
private Context context;
private Industry industries;
public IndustryAdapter(Context context, Industry industries) {
this.industries = industries;
this.context = context;
}
@Override
public int getCount() {
return 1;
}
@Override
public Object getItem(int position) {
return 1;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
convertView = inflater.inflate(R.layout.row_item, parent, false);
}
TextView tvName = (TextView)convertView.findViewById(R.id.tvName);
TextView tvDescription = (TextView)convertView.findViewById(R.id.tvDescription);
String name = industries.getName();
String descr = industries.getDescription();
tvName.setText(name);
tvDescription.setText(descr);
return convertView;
}
private Context getContext() {
return context;
}
问题在于此行: 字符串名称= industries.getName(); 字符串descr = industries.getDescription();
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String al.sqmo.model.Industry.getName()' on a null object reference