Hello.

This is my main class, which helps to displays data out of a database
in list format. It also handles a "ADD"and a "Delete" Button:


/**
 * A list view example where the
 * data for the list comes from an array of strings.
 */
public class TeaTime extends ListActivity {

        private static final int ACTIVITY_CREATE=0;
    private static final int ACTIVITY_EDIT=1;

    private TeaDB myDBHelper;
        private Cursor myTeaCursor;

        private static final int ADD_ID = Menu.FIRST;
        private static final int DELETE_ID = Menu.FIRST + 1;

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.main);
        myDBHelper = new TeaDB(this);
        myDBHelper.open();
        fillData();
        myDBHelper.close();
    }



    private String[] mStrings = {
            "Green Tea","Black Tea","Fruit Tea","Peppermint Tea"};

    /**
     * Get all Teas in an array to display on the screen
     */
    private void fillData() {
        // Get all of the rows from the database and create the item list
        myTeaCursor = myDBHelper.callUpAllTeas();
        startManagingCursor(myTeaCursor);

        // Create an array to specify the fields we want to display in
the list (only NAME)
        String[] from = new String[]{TeaDB.KEY_NAME};

        // and an array of the fields we want to bind those fields to
(in this case just text1)
        int[] to = new int[]{R.id.list};

        // Now create a simple cursor adapter and set it to display
 //       SimpleCursorAdapter tea =
  //                new SimpleCursorAdapter(this, R.layout.main,
myTeaCursor, from, to);
   //     setListAdapter(tea);

        ListAdapter test = new SimpleCursorAdapter(this,
R.layout.main, myTeaCursor, from, to);
        setListAdapter(test);
       // setListAdapter(new ArrayAdapter<String>(this,
        //android.R.layout.simple_list_item_1, from));


    }

    /**
     * Create the Menu (Add + Delete)
     */
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        menu.add(0, ADD_ID, R.string.menu_add);
        menu.add(0, DELETE_ID, R.string.menu_delete);
        return true;
    }

    /**
     * Activity Handler for the menu buttons (Add + Delete)
     */
    public boolean onMenuItemSelected(int featureId, Item item) {
        switch(item.getId()) {
        case ADD_ID:
            createTea();
            return true;
        case DELETE_ID:
            myDBHelper.deleteTea(4);
            //fillData();
            return true;
        }

        return super.onMenuItemSelected(featureId, item);
    }

    /**
     */
    private void createTea() {
        Intent i = new Intent(this, TeaEdit.class);
        startSubActivity(i, ACTIVITY_CREATE);
  }


If you press the "ADD" Button you come to the following activity which
allows you to add data. When I press the Button "CONFIRM" the saving
of the data in the database works, but also the error message
mentioned above shows up:


public class TeaEdit extends Activity {

        private EditText myNameText;
    private EditText myBrewTimeText;
    private Long myRowId;
    private TeaDB myDBHelper;

    @Override
    protected void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.tea_add);

        myNameText = (EditText) findViewById(R.id.name);
        myBrewTimeText = (EditText) findViewById(R.id.brewTime);

        Button confirmButton = (Button) findViewById(R.id.confirm);

        myDBHelper = new TeaDB(this);
        myDBHelper.open();

        confirmButton.setOnClickListener(new View.OnClickListener() {

            public void onClick(View view) {

                myDBHelper.createTea(myNameText.getText().toString(),
Integer.valueOf(myBrewTimeText.getText().toString()));
                myDBHelper.close();
                setResult(RESULT_OK, null, null);
                finish();
            }

        });
    }
}


So if it helps, it would be great. Can you also please tell me where I
can find the "stack trace in logcat"?

Thank you
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to