I have saved my image as a blob to the SQlite Database (or i think it has saved it) byt when loading the activity again it crashes with this error:
12-24 16:06:47.919: E/AndroidRuntime(19689): FATAL EXCEPTION: main
12-24 16:06:47.919: E/AndroidRuntime(19689): Process: com.example.main, PID: 19689
12-24 16:06:47.919: E/AndroidRuntime(19689): android.database.CursorIndexOutOfBoundsException: Index 1 requested, with a size of 1
12-24 16:06:47.919: E/AndroidRuntime(19689): at android.database.AbstractCursor.checkPosition(AbstractCursor.java:426)
12-24 16:06:47.919: E/AndroidRuntime(19689): at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:136)
12-24 16:06:47.919: E/AndroidRuntime(19689): at android.database.AbstractWindowedCursor.getBlob(AbstractWindowedCursor.java:44)
12-24 16:06:47.919: E/AndroidRuntime(19689): at android.database.CursorWrapper.getBlob(CursorWrapper.java:122)
Okay so here is how i save the image:
contentValues.put(LocationsDB.FIELD_IMAGE, imageData);
....
baos = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.JPEG, 100, baos);
imageData = baos.toByteArray();
Then when loading the image:
public void onLoadFinished(Loader<Cursor> arg0, Cursor arg1) {
int locationCount = 0;
double lat=0;
double lng=0;
float zoom=0;
locationCount = arg1.getCount();
arg1.moveToFirst();
for(int i=0;i<locationCount;i++){
// Get the latitude
lat = arg1.getDouble(arg1.getColumnIndex(LocationsDB.FIELD_LAT));
lng = arg1.getDouble(arg1.getColumnIndex(LocationsDB.FIELD_LNG));
zoom = arg1.getFloat(arg1.getColumnIndex(LocationsDB.FIELD_ZOOM));
arg1.getBlob(arg1.getColumnIndex(LocationsDB.FIELD_IMAGE));
thePoint = new LatLng(lat, lng);
drawMarker(thePoint);
}
if(locationCount>0){
googleMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(lat,lng)));
googleMap.animateCamera(CameraUpdateFactory.zoomTo(zoom));
arg1.moveToNext();
ImageView image = (ImageView) findViewById(R.id.marker_icon);
imageData = arg1.getBlob(arg1.getColumnIndex("image"));
image.setImageBitmap(BitmapFactory.decodeByteArray(imageData, 0, imageData.length));
}
}
What am i doing wrong here?
Aucun commentaire:
Enregistrer un commentaire