This is my first time working with SQLite in the Android environment. I am trying to insert a photo and the coordinates of the user when the photo is taken, into an SQLite DB.
It seemed to have worked fine last night (Home Computer) when I tried to insert the photo into the DB, no exceptions, although I couldn’t find where the tablet was creating the DB, I tried looking in the data folder through the File Explorer in Eclipse DDMS but there was nothing in there, using the Windows file Explorer I have Computer\SCH-I905\Tablet\Android\data with com.app etc but my package is not present.
This morning (Work Computer) I am getting a fatal StackOverflowError exception. Is there something I am doing wrong with my code?? I am converting the image to byte[] then storing to the DB as a Blob, I am using the byte[] instead of converting the byte[] to String due to some recommendations I read against Strings to Blob. Any help or recommendation is MUCH appreciated, thanks.
P.S. I don’t have anything in my code converting string toUpperCase()
Background:
- Google APIs 12
- Testing on the Samsung Galaxy 10.1 4G LTE Tablet
- I’m developing on two different computers (Home and Work), presently I copy files to a thumb drive then load them into my Workspace and start Eclipse. I have to uninstall the app due to conflicting signatures and then re-run the application through Eclipse.
Here I convert the image to byte[] then post to database:
public Camera.PictureCallback jpegHandler = new Camera.PictureCallback(){
public void onPictureTaken(byte[] jpeg, Camera camera ){
// TODO Work on the image insertion into the database
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
image = BitmapFactory.decodeByteArray(jpeg, 0, jpeg.length);
image.compress(Bitmap.CompressFormat.PNG, 100, bos);
byte[] imageBlob = bos.toByteArray();
UpdateGeoLocation updateGeo = new UpdateGeoLocation(getApplicationContext());
double picLat = updateGeo.returnlocation.getLatitude();
double picLng = updateGeo.returnlocation.getLongitude();
Log.i("imageBlob", "" + imageBlob);
Log.i("phoLat", "" + picLat);
Log.i("phoLng", "" + picLng);
dbControl.open();
dbControl.addItem(imageBlob, picLat, picLng);
dbControl.close();
Log.i("InsertPhotoIntoDB", "WORKED!");
} catch (SQLiteException e) {
Log.e("InsertPhotoIntoDB", "FAILED: " + e.getMessage());
}
Here is a snippet of my DatabaseHelper.Java
public class GlobalDBVars {
public static final String DATABASE_NAME = "NST.db";
public static final int DATABASE_VERSION = 2;
public static final String TABLE_NAME = "photos_withCoordinates";
public static final String KEY_ROWID = "_id";
public static final String KEY_PHOTOS = "_photo";
public static final String KEY_LAT = "_lat";
public static final String KEY_LNG = "_lng";
}
private static final String DATABASE_CREATE = "CREATE TABLE IF NOT EXISTS " +
GlobalDBVars.TABLE_NAME + "(" +
GlobalDBVars.KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
GlobalDBVars.KEY_PHOTOS + " BLOB NOT NULL, " +
GlobalDBVars.KEY_LAT + " REAL NOT NULL, " +
GlobalDBVars.KEY_LNG + " REAL NOT NULL);";
@Override
public void onCreate(SQLiteDatabase db) {
try {
db.execSQL(DATABASE_CREATE);
onCreate(db);
Log.i(TAG, "onCreate db: " + DATABASE_CREATE);
} catch (SQLException e) {
Log.e(TAG, "FAILED: " + e.getMessage());
}
}
Insert statement within DatabaseControl.Java
public long addItem(byte[] photos, double _lat, double _lng) {
ContentValues setUpVals = createContentValues(photos, _lat, _lng);
return database.insert(GlobalDBVars.TABLE_NAME, null, setUpVals);
}
LogCat:
09-04 10:08:48.160: I/imageBlob(21529): [B@40751c18
09-04 10:08:48.160: I/phoLat(21529): 37.3674153
09-04 10:08:48.160: I/phoLng(21529): -77.4001403
09-04 10:08:48.240: I/dalvikvm(21529): threadid=1: stack overflow on call to Ljava/util/Locale;.getLanguage:L
09-04 10:08:48.240: I/dalvikvm(21529): method requires 8+20+0=28 bytes, fp is 0x58f53318 (24 left)
09-04 10:08:48.240: I/dalvikvm(21529): expanding stack end (0x58f53300 to 0x58f53000)
09-04 10:08:48.240: I/dalvikvm(21529): Shrank stack (to 0x58f53300, curFrame is 0x58f56d8c)
09-04 10:08:48.240: D/AndroidRuntime(21529): Shutting down VM
09-04 10:08:48.240: W/dalvikvm(21529): threadid=1: thread exiting with uncaught exception (group=0x40105760)
09-04 10:08:48.270: D/dalvikvm(21529): GC_CONCURRENT freed 95K, 8% free 8606K/9287K, paused 2ms+2ms
09-04 10:08:48.310: E/AndroidRuntime(21529): FATAL EXCEPTION: main
09-04 10:08:48.310: E/AndroidRuntime(21529): java.lang.StackOverflowError
09-04 10:08:48.310: E/AndroidRuntime(21529): at java.lang.CaseMapper.toUpperCase(CaseMapper.java:143)
09-04 10:08:48.310: E/AndroidRuntime(21529): at java.lang.String.toUpperCase(String.java:1619)
09-04 10:08:48.310: E/AndroidRuntime(21529): at android.database.DatabaseUtils.getSqlStatementType(DatabaseUtils.java:1245)
09-04 10:08:48.310: E/AndroidRuntime(21529): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:100)
09-04 10:08:48.310: E/AndroidRuntime(21529): at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:59)
09-04 10:08:48.310: E/AndroidRuntime(21529): at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1931)
09-04 10:08:48.310: E/AndroidRuntime(21529): at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1864)
09-04 10:08:48.310: E/AndroidRuntime(21529): at sompackage.nst.DatabaseHelper.onCreate(DatabaseHelper.java:49)
You’re calling
onCreate()recursivelyRemove that
onCreate(db)call