I'm working on an android app that saves a couple of text field inputs to a SQLite database. When I try to do so though, the app crashes and I don't know what exactly it is I'm doing wrong. Though I'm certain the error is coming from the lines where I open and write to the database.
// Instantiate onClickListener for addFoodItemSubmitButton
addFoodItemSubmitButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Read user input for food item
String foodItemName = ((EditText) findViewById(R.id.foodItemNameField)).toString();
String foodItemExpirationDate = ((EditText)findViewById(R.id.foodItemExpirationDateField)).toString();
// Insert values into SQLite Database
SQLiteDatabase db = openOrCreateDatabase("FoodItemDB", MODE_PRIVATE, null);
db.execSQL("INSERT INTO FoodItems VALUES(" + foodItemName + "VARCHAR" + foodItemExpirationDate + "VARCHAR" + ")");
db.close();
Date expirationDate = stringtoDate(foodItemExpirationDate, "/");
// Set notificationTask timer
// TODO: add notificationTask that triggers before expirationDate
//Timer expirationTimer = new Timer(notificationTask, expirationDate);
Intent intent = new Intent(view.getContext(), MainActivity.class);
startActivity(intent);
}
});
This is the listener class for my submit button for the form.
Aucun commentaire:
Enregistrer un commentaire