Search code examples
androidimagesqlitearraysput

Android trying to put image as a ByteArray into sqlite database, getting error on put method


I'm trying to enter an image into a database together with some strings, but I get the following error on my put method:

The method put(String, String) in the type ContentValues is not applicable for the arguments (String, Byte[]) 

But when I see it in tutorials, it seems to be done exactly like how I do it.

Here's the relevant code:

private static final String DATABASE_CREATE = 
    "CREATE Table " + DATABASE_TABLE_LIST + " ( "
    + LIST_ID + " integer PRIMARY KEY Autoincrement, "
    + LIST_NAME + " text NOT NULL, "
    + LIST_ADDRESS + " text NOT NULL, " 
    + LIST_IMAGE + " BLOB );";

...

public long createItem(String name, String address, Byte[] image) {
    ContentValues initialValues = new ContentValues();
    initialValues.put(LIST_NAME, name);
    initialValues.put(LIST_ADDRESS, address);
    initialValues.put(LIST_IMAGE, image);
    return mDb.insert(DATABASE_TABLE_LIST, null, initialValues);
}

I guess it might have something to do with putting strings as well as the bytearray, but I wouldn't know how to solve it and can't find it through Googling


Solution

  • It seems strange to me that you try to insert a B yte array. Your image data is most probably a b yte array. As there is no put method for arrays of Byte objects but only for arrays of the primitive data type byte the compiler has no clue what to do.