In my project im using sqlite database to save pictures and their locations. i get this error while trying to insert the data into my database:
E/SQLiteLog: (20) statement aborts at 5: [INSERT INTO PHOTO VALUES(NULL,?,?,?,?)] datatype mismatch
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.tomer.finalproject, PID: 18550
android.database.sqlite.SQLiteDatatypeMismatchException: datatype mismatch (code 20)
at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method)
at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:786)
at android.database.sqlite.SQLiteSession.executeForLastInsertedRowId(SQLiteSession.java:926)
Here is my code:
the insert method which is inside the class called SQLiteOpenHelper:
public void insertData(String name, String lat, String lon, byte[] image) {
SQLiteDatabase database = getWritableDatabase();
String sql = "INSERT INTO PHOTO VALUES(NULL,?,?,?,?)";
SQLiteStatement statement = database.compileStatement(sql);
statement.clearBindings();
statement.bindString(1, name);
statement.bindString(2, lat);
statement.bindString(3, lon);
statement.bindBlob(4, image);
statement.executeInsert();
}
I call this in a button 'add' from another activity :
Those 2 lines are under onCreate
sqLiteHelper=new SQLiteHelper(this,"GalleryDB.sqlite",null,1);
sqLiteHelper.queryData("CREATE TABLE IF NOT EXISTS PHOTO (name VARCHAR,lat VARCHAR,lon VARCHAR,image BLOG,Id INTEGER PRIMARY KEY AUTOINCREMENT)");
and this is my add Button:
btnadd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
GPStracker g = new GPStracker(getApplicationContext());
Location l = g.getLocation();
if (l != null) {
double lat = l.getLatitude();
double lon = l.getLongitude();
String stLat= String.valueOf(lat);
String stLon= String.valueOf(lon);
try{
Toast.makeText(getApplicationContext(), "Saved To Gallery!", Toast.LENGTH_SHORT).show();
sqLiteHelper.insertData(etname.getText().toString().trim(),stLat.trim(),stLon.trim(),imageViewToByte(imageView));
}
catch (Exception e){
e.printStackTrace();
}
}
}
});
Just want to point out that everything was working until my Laptop crushed and i had to change to another one.
Thank you for your help.