I was able to enter information into the database by using the getReadableDatabase()
method. Should not that be a mistake then? Should not be the getWritableDatabase()
method?
private void savePet() {
petDbHelper = new PetDbHelper(this);
db = petDbHelper.getReadableDatabase();
ContentValues values = new ContentValues();
values.put(PetEntry.COLUMN_PET_NAME, mNameEditText.getText().toString());
values.put(PetEntry.COLUMN_PET_BREED, mBreedEditText.getText().toString());
values.put(PetEntry.COLUMN_PET_WEIGHT, mWeightEditText.getText().toString());
values.put(PetEntry.COLUMN_PET_GENDER, mGender);
long newRowID =
db.insert(PetEntry.TABLE_NAME, null, values);
/** Display rowID after finish */
Toast.makeText(this, "New row added: " + newRowID, Toast.LENGTH_SHORT).show();
/** Close Activity */
finish();
}