My db4o database is not updating. In my ViewContact class I have a button that when pressed asks a user for an input, and stores it in the database. It's not storing any ideas?
I have posted the problem code below of the ViewContact class,
@SuppressLint({ "ParserError", "ParserError", "ParserError", "ParserError" })
public void onClick(View v) {
switch(v.getId())
{
/*THIS IS THE ADD PHRASE BUTTON*/
case R.id.bAddP:
/*ALERT BOX LAUNCHES*/
final AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Title");
alert.setMessage("Message");
/* Set an EditText view to get user input */
final EditText input = new EditText(this);
alert.setView(input);
/*THIS IS FOR WHEN OK IS PRESSED*/
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
/*VALUE OF USER INPUT*/
String value = input.getText().toString();
/* OPEN DB4O AND UPDATE CONTACT OBJECT*/
ObjectContainer db = Db4oEmbedded.openFile(Db4oEmbedded
.newConfiguration(), db4oDBFullPathSdCard(context));
try {
/*QUERY BY EXAMPLE TO GET CONTACT
USING "t" WHICH IS PARCELABLE OBJECT PASSED FROM
FIRST ACTIVITY*/
ObjectSet result = db.queryByExample(new NewContact(t.getName()));
NewContact found = (NewContact) result.next();
/*storePhrase STORES A STRING INTO THE OBJECTS
ARRAYLIST*/
found.storePhrase(value);
/*UPDATE DATABASE,
THIS IS NOT UPDATING! HERE IS PROBLEM*/
db.store(found);
Class ourContact = Class.forName("com.text.q.ViewContacts");
Intent i = new Intent(ViewContact.this, ourContact);
//REPARCEL OBJECT SO NAME CAN BE USED AGAIN
i.putExtra("New", t);
finish();
startActivity(i);
/*REFRESH ACTIVITY*/
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally {
db.close();
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Canceled.
}
});
alert.show();
break;
}
}
The problem lies in the onClick method, for bAddP. I'm trying to update the database so that when i end and restart the activity the new phrase will be displayed. The line "db.store(found);" should update my database, but it doesn't. I realise this isn't perfect code so any ideas are grateful. Thanks
It's okay I figured it out, it was to do with the updating depth.