Hello,  I am using a simple list and I am getting this exception.  I
get the error with the _ID in or out of the projection. when calling
SimpleCursorAdaptor.  The DB insert/guery is working.
Anyone seen this problem?
thanks

 private static final String[] PROJECTION = new String[] {
        Meds._ID,
        //Meds.sSOURCE,
        Meds.sPRODUCT,
        //Meds.sDIRECTIONS,
        //Meds.sFULLFILLHISTORY,

    };

  protected void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        Log.e(TAG, "OnCreate");
        setDefaultKeyMode(DEFAULT_KEYS_SHORTCUT);

        Intent intent = getIntent();
        if (intent.getData() == null) {
            intent.setData(Meds.CONTENT_URI);
        }

        // Inform the list we provide context menus for items
        getListView().setOnCreateContextMenuListener(this);

        setContentView(R.layout.medlist);

        // Perform a managed query. The Activity will handle closing
and re-querying the cursor
        // when needed.

        //Uri uri = getIntent().getData();
        //Cursor cursor = managedQuery(uri, PROJECTION, null, null,
null);
        Cursor cursor = managedQuery(Meds.CONTENT_URI, PROJECTION,
null, null, null);

        Log.e(TAG, "OnCreate cursor.getCount = " + cursor.getCount());
        /* Used to map meds entries from the database to views
         */
        SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,

R.layout.mphrlist_item,
 
cursor,
                                                              new
String[] { MPhrDef.Meds.sPRODUCT }, //from
                                                              new int
[] { android.R.id.text1 });      //to
        Log.e(TAG, "!!OnCreate cursor = " +adapter.convertToString
(cursor));

        setListAdapter(adapter);

    }//onCreate
--
 public static final String TITLE = "title";
            public static final String _ID = "_ID";
            public static final String sMEDS_FK = "MEDS_FK";
            public static final String sSTATUS="STATUS";
            public static final String sSOURCE = "SOURCE";
            public static final String sPRODUCT = "PRODUCT";
            public static final String sDIRECTIONS = "DIRECTIONS";
            public static final String sFULLFILLHISTORY =
"FULLFILLHISTORY";
            public static final String sCREATION_DATE =
"CREATION_DATE";
            public static final String sMODIFIED_DATE =
"MODIFIED_DATE";

        public String MEDCOLSTR = _ID + " INTEGER PRIMARY KEY,"
             + sMEDS_FK + " INTEGER ,"
             + sSTATUS + " TEXT,"
             + sSOURCE + " TEXT,"
             + sPRODUCT + " TEXT,"
             + sDIRECTIONS + " TEXT,"
             + sFULLFILLHISTORY+ " TEXT,"
             + sCREATION_DATE + " TEXT,"
             + sMODIFIED_DATE + " TEXT";

------
ContentProvider

   public Uri insert(Uri uri, ContentValues initialValues) {
        Log.e(TAG, "insert ContentValues = " +initialValues);
        // Validate the requested uri
        if (sUriMatcher.match(uri) != MEDS) {
            throw new IllegalArgumentException("Unknown URI " + uri);
        }

        //setup to insert a row into db
        ContentValues values;
        if (initialValues != null) {
            values = new ContentValues(initialValues);
        } else {
            values = new ContentValues();
        }

        Long now = Long.valueOf(System.currentTimeMillis());

        // Make sure that the fields are all set.  IF not set them

        if (values.containsKey(Meds.sMODIFIED_DATE) == false) {
            values.put(Meds.sMODIFIED_DATE, now);
        }

        if (values.containsKey(Meds.sSOURCE) == false) {
            values.put(Meds.sSOURCE, now);
        }

        if (values.containsKey(Meds.sCREATION_DATE) == false) {
            values.put(Meds.sSOURCE, now);
        }
        Log.e(TAG, "_ID = " + values.getAsInteger(Meds._ID));
        SQLiteDatabase db;
        if(mOpenHelper != null){
           db = mOpenHelper.getWritableDatabase();
        }else{
                Log.e(TAG, "ERROR:insert mOpenHelper = NULL");
                return null;
        }
        //insert the entire row into DB
        long rowId = db.insert(MEDS_TABLE_NAME, Meds.MED, values);

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to