用のカスタムアダプターがありますListView
。それはで私NullPointerException
を与えますsetAdapter
。コードを何度か調べましたが、NPE の原因がわかりませんでした。関連するコード スニペットは次のとおりです。
アクティビティ:
ListView mListView;
Vector<DashboardBean> dashboardBean= new Vector<DashboardBean>();
MyCustomAdapter adapter;
adapter = new MyCustomAdapter(MyDashboardActivity.this,
R.layout.testdashboard_row, dashboardBean);
adapter.clear();
dashboardBean.add(new DashboardBean(projects, workRequests, status));
mListView.setAdapter(adapter);
ダッシュボードビーン:
public class DashboardBean {
public String project;
public String workRequest;
public String startDate;
public String status;
public String actualHours;
public String actualMins;
public DashboardBean(String project, String workRequest,String status)
{
this.project = project;
this.workRequest = workRequest;
this.status = status;
}
}
カスタムアダプタ:
public class MyCustomAdapter extends ArrayAdapter<DashboardBean> {
Context context;
int layoutResourceId;
DashboardBean currentMRB;
Vector<DashboardBean> data;
public MyCustomAdapter(Context context, int layoutResourceId, Vector<DashboardBean> data)
{
super(context,layoutResourceId,data);
this.layoutResourceId = layoutResourceId;
this.context=context;
this.data = data;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
MyStringReaderHolder holder;
if(row==null)
{
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent,false);
holder= new MyStringReaderHolder();
holder.project = (TextView)row.findViewById(R.id.project);
holder.workRequest = (TextView)row.findViewById(R.id.work_request);
holder.status = (TextView) row.findViewById(R.id.status);
row.setTag(holder);
}
else
{
holder=(MyStringReaderHolder) row.getTag();
}
DashboardBean mrb = data.elementAt(position);
holder.project.setText(mrb.project);
holder.workRequest.setText(mrb.workRequest);
holder.status.setText(mrb.status);
return row;
}
static class MyStringReaderHolder
{
TextView project, workRequest, startDate, status, actualHours;
}
}
誰でも助けてもらえますか?