0
I saved an image by turning it into a byte array, in a column in the Sqlite data-type byte.
When I do a cursor to fetch this image from the bank using the class Cursor and the method get_blob()
, says he can’t convert.
What I’m doing wrong?
public List<Locais> listaDeMemorias() {
DataBaseApp dtbApp = new DataBaseApp( this );
SQLiteDatabase dtb = dtbApp.getReadableDatabase();
try {
Cursor c = dtb.rawQuery("select idLocal,dsLocal,dtVisita,dsObservacoes,imagem from Locais", null);
Date data = new Date(System.currentTimeMillis());
while (c.moveToNext()) {
System.out.println("Tem dados");
int id = c.getInt( 0 );
System.out.println( "ID: " + id );
byte[] imgData = c.getBlob(4);
Bitmap img = BitmapFactory.decodeByteArray( imgData, 0, imgData.length);
Locais locais = new Locais(c.getInt(0),c.getString(1),new Timestamp( c.getLong( 2 )),c.getString(3),img);
System.out.println( "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" );
listaLocais.add(locais);
}
return listaLocais;
} catch ( Exception e ) {
System.out.println( e.getMessage() );
} finally {
dtb.close();
}
System.out.println( "Enviando lista de locais: " + listaLocais.size() );
return listaLocais;
}
Show how you are using the method
get_blob
.– ramaral
A common error in the use of methods get class Cursor has to do with the correct indexing of the fields. In your case you are doing it correctly.
– ramaral
I don’t know what it might be! It falls on Exception right on that line q calls the get_blob
– David Melo
How are you declaring the column image
– ramaral
Type of data: bytea
– David Melo
Byte or Blob?
– ramaral
"bytea", is a data type of sqlite
– David Melo
I don’t know this guy. Look at my answer.
– ramaral
I will try to change to see c right! Warning c be!
– David Melo
The q da message is as follows: INTEGER data in nativeGetBlob
– David Melo
Show the code where you convert to byte array and the one that writes.
– ramaral
I did it! I changed the column in sqlite to blob. But the problem was not this, at the time of entering in the bank I was inserting other information in the column image. I reviewed the code and found.
– David Melo