I am working on a program that writes files to a database that is copied from the assets of the application. The copy works fine. However when I try to write to the DB It doesn't error out, logcat shows nothing, but the DB will not change. I pull the DB out of the emulater using the DDMS window then open it with SQLLite browser. The database is default as if nothing was inserted. Not sure what is going on. Can anyone help? (code below).
This is in a class I created called DBAdapter.java. This is what is called in the class of the application.
This is in a class called InputGame.java.
This is in a class I created called DBAdapter.java. This is what is called in the class of the application.
Code:
//---insert a game into the database---
public long insertGame(Integer id, Integer user_id, String title, String esrb, String genre, Integer rating, String review, Integer pic_id)
{
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_ID, id);
initialValues.put(KEY_USER_ID, user_id);
initialValues.put(KEY_TITLE, title);
initialValues.put(KEY_ESRB, esrb);
initialValues.put(KEY_GENRE, genre);
initialValues.put(KEY_RATING, rating);
initialValues.put(KEY_REVIEW, review);
initialValues.put(KEY_PICID, pic_id);
return db.insert(DATABASE_TABLE1, null, initialValues);
}
This is in a class called InputGame.java.
Code:
DBAdapter db = new DBAdapter(this);
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.inputgame);
Spinner s = (Spinner) findViewById(R.id.spnRatings);
ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.ratings, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s.setAdapter(adapter);
Spinner s1 = (Spinner) findViewById(R.id.spnGenre);
ArrayAdapter adapter1 = ArrayAdapter.createFromResource(this, R.array.genre, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s1.setAdapter(adapter1);
RatingBar ratingbar = (RatingBar) findViewById(R.id.rbRating);
ratingbar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
Toast.makeText(InputGame.this, "New Rating: " + rating, Toast.LENGTH_SHORT).show();
}
});
Button btnAddGame = (Button) findViewById(R.id.btnGSubmit);
btnAddGame.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
EditText txtTitle = (EditText) findViewById(R.id.edtTitle);
EditText txtReview = (EditText) findViewById(R.id.Review);
Spinner s = (Spinner) findViewById(R.id.spnRatings);
Spinner s1 = (Spinner) findViewById(R.id.spnGenre);
RatingBar ratingbar = (RatingBar) findViewById(R.id.rbRating);
String Title = txtTitle.getText().toString();
String Genre = s1.getSelectedItem().toString();
String ESRB = s.getSelectedItem().toString();
Integer Stars = ratingbar.getNumStars();
String Review = txtReview.getText().toString();
db.open();
long id;
id = db.insertGame(
00001, 00001, Title, ESRB, Genre, Stars, Review, 00001);
db.close();
Toast.makeText(InputGame.this, "Save Successful!", Toast.LENGTH_SHORT).show();
}
});