1
我得到一個空ponter在lv1.setAdapter(myAdapter)
,我不明白爲什麼。有人可以看到最新的錯誤?自定義BaseAdapter空指針
我想實現兩線列表
MyActivity.class
final ListView lv1 = (ListView) findViewById(R.id.ListView01);
Log.d("",topicTitle.toString() + "----------" + topicAuthor.toString()); //not null
MyCustomBaseAdapter myAdapter = new MyCustomBaseAdapter(DiscussionTopics.this, topicTitle , topicAuthor);
lv1.setAdapter(myAdapter);
MyCustomBaseAdapter.class
public class MyCustomBaseAdapter extends BaseAdapter {
private static ArrayList<String> topics;
private static ArrayList<String> author;
private LayoutInflater mInflater;
public MyCustomBaseAdapter(Context context, ArrayList<String> topics, ArrayList<String> author) {
this.topics = topics;
this.author = author;
mInflater = LayoutInflater.from(context);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.custom_row_view, null);
holder = new ViewHolder();
holder.title = (TextView) convertView.findViewById(R.id.title);
holder.author = (TextView) convertView.findViewById(R.id.author);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.title.setText(topics.get(position));
holder.author.setText(author.get(position));
return convertView;
}
static class ViewHolder {
TextView title;
TextView author;
}
public int getCount() {
// TODO Auto-generated method stub
return topics.size();
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return topics.get(position);
}
}
你能幫助我們多一點,給行號,給予了NPE的佈局? –
@FrankSposaro它出現在行'lv1.setAdapter(myAdapter);' – code511788465541441
我猜'lv1'是'null',因爲你沒有在活動上設置任何內容......我們已經看到了十幾篇文章,就像這在過去的日子裏 –