listView1.setAdapter(adapter)上的以下错误,带有setApdater的空对象引用。我想第二列索引设置为null。
historyActivity.java
public class historyActivity extends MainActivity {
private TextView mTextMessage;
Intent intent = new Intent();
DatabaseHelper myDB;
ArrayList<User> userList;
ListView listView1;
User user;
ThreeColumn_ListAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history);
myDB = new DatabaseHelper(this);
userList = new ArrayList<>();
Cursor data = myDB.getListContents();
int numRows = data.getCount();
if(numRows ==0){
Toast.makeText(historyActivity.this, "Nothing in the db",Toast.LENGTH_LONG).show();
}
else{
int i = 0;
while(data.moveToNext()){
user = new User(data.getString(1), data.getString(2), data.getString(3));
userList.add(user);
}
adapter = new ThreeColumn_ListAdapter(this,R.layout.viewcontents_layout,userList);
listView1 = (ListView)findViewById(R.id.listView);
listView1.setAdapter(adapter);
}
}
}