开发者

Save image path name from sdcard to Sqlite database

am having a little trouble here. i am trying to store and retrieve images from an sqlitedatabase by storing their image path name. the images are stored in the sdcard. I tried this code, but its not working.

saving image path:

 String filename = "/sdcard/barn.jpg"

ContentValues vals2 = new ContentValues(); //create content values and store it.
   vals.put(ImageDB.SHOW, filename);
   imagedb.tagImage(vals2);


public long tagImage(ContentValues val){
        Log.d(TAG,"tagged Images");
        return db.insert(DATABASE_TABLE, null, val);
    }

retrieving :

Cursor cursor = imagedb.retrieveTag(tag);

    /*method for retrieving*/

    public Cursor retrieveTag(String tag){
    Stri开发者_C百科ng[] condition = {tag)};
    Cursor cursor = db.query(DATABASE_TABLE, condition, null, null, null, null, null);
        cursor.moveToNext();
        return cursor;
    }

The cursor is not returning anything and i sometimes get a CursorIndexOutofBoundsException. Is this a correct way to save and retrieve from an sqlitedatabase or does the filename pose a problem for the sqlite database?.. How can i store it correctly?.. Thank you.


Try getting the root directory with Environment.getExternalStorageDirectory(), harcoding "/sdcard/" may not work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜