vendredi 20 mars 2015

Unable to convert BLOB to String

In my code, user supposed to add details of a product including name, image, category, and other detail. But after entering the data and saved it, it cannot view the data that they input in, instead it is showed unable to convert BLOB to String.


My coding for adding data.



items Item= new items();
db.getWritableDatabase();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
byte imageInByte[] = stream.toByteArray();
Bitmap bMap= BitmapFactory.decodeByteArray(imageInByte, 0, imageInByte.length);
ivThumbnailPhoto.setImageBitmap(bMap);
Item.setName(name.getText().toString());
Item.setCategory(SpCate.getSelectedItem().toString());
Item.setDetails(details.getText().toString());
Item.setImage(imageInByte);
db.addItemSpinner(new items());
// Save the Data in Database
MyDb entry= new MyDb(SellingItem.this);
entry.getWritableDatabase();
entry.addItemSpinner(Item);
entry.close();
Toast.makeText(getApplicationContext(), "Account Successfully Created ", Toast.LENGTH_LONG).show();
Log.d("name", Item.getName());
Log.d("category", Item.getCategory());
Log.d("detailsL", Item.getDetails());
Intent i=new Intent(SellingItem.this,SearchItem.class);
startActivity(i);


My Database to input data.



public void addItemSpinner(items i)
{
SQLiteDatabase db = this.getWritableDatabase();

ContentValues values = new ContentValues();
values.put(COLUMN_NAME, i.name); // Contact Name
values.put(COLUMN_IMAGE, i.image); // Contact Phone
values.put(COLUMN_CATE, i.category); // Contact Name
values.put(COLUMN_DETAILS, i.details); // Contact Phone

// Inserting Row
db.insert(TABLE_NAME, null, values);
db.close(); // Closing database connection
}


logcat shows like this.



java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.projectonline/com.example.projectonline.SearchItem}: android.database.sqlite.SQLiteException: unknown error (code 0): Unable to convert BLOB to string

Aucun commentaire:

Enregistrer un commentaire