I am trying to make a database connection with my app. It has an allow and deny button for a visitor. Whenever I try to call an operation of the database class my app force closes. For example, When I click on the Allow button I want the app to store the visitor id, date and string response in the database.
Following is the code in the mainActivity that I have for the button:
//databaseVisitor VisDB = new databaseVisitor (this);
//VisitorDatabase VDB = new VisitorDatabase();
//Defining the actions of the Allow Button
Button.OnClickListener allowListener = new Button.OnClickListener(){
public void onClick(View arg0) {
// TODO Auto-generated method stub
Toast allowToast = Toast.makeText(MainActivity.this, R.string.toastYes, Toast.LENGTH_LONG);
allowToast.show();
//Log.d("Insert Log: ", "Inserting add log..");
//count = VisDB.getVisitorCount();
response = "Access Granted";
//dt = date.getDate();
//VisDB.addVisitor(new VisitorDatabase(count+1, dt, response));
}
};
its most probably because you are closing the cursor
and then making operations on it
try smthg like this
EDIT :
and as for VisDB do it like that