db4o没有更新我的对象的数组列表

时间:2012-07-24 13:57:19

标签: android database eclipse db4o updating

我的db4o数据库没有更新。在我的ViewContact类中,我有一个按钮,按下时会询问用户输入,并将其存储在数据库中。它没有存储任何想法?

我已经发布了ViewContact类的下面的问题代码,

@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;



}






}

问题在于onClick方法,对于bAddP。我正在尝试更新数据库,以便当我结束并重新启动活动时,将显示新短语。行“db.store(found);”应该更新我的数据库,但事实并非如此。我意识到这不是完美的代码所以任何想法都是感激的。 感谢

1 个答案:

答案 0 :(得分:0)

没关系,我想出来了,这与更新深度有关。