Reputation: 6063
Good day, Just to make it short with relevant code,
If i do this in my activity:
Intent i = getIntent();
Bundle extras = i.getExtras();
BitmapFactory.Options bf = new BitmapFactory.Options();
bf.inSampleSize = 2;
filename = extras.getString("pic_name");
ImageView iv = new ImageView(getApplicationContext());
Bitmap bm = BitmapFactory.decodeFile(filename, bf);
iv.setImageBitmap(bm);
setContentView(iv);
registerForContextMenu(iv);
public boolean onContextItemSelected(MenuItem item){
// weatherimagedb = new WeatherImageDB(this);
//weatherimagedb.open();
ContentValues vals = new ContentValues();
int selection = item.getItemId();
switch(selection){
case Holidays:
vals.put(ImageDB.HOLIDAYS, filename);
break;
case Weather:
vals.put(ImageDB.WEATHER, filename);
break;
}
imagedb.tagImage(filename, vals); //logcat error is here
return true;
}
And in the imageDB database class i have a method like this:
public long tagImage(String pathname, ContentValues val){
return db.insert(DATABASE_TABLE, null, val); //logcat error is here
}
i get this error in database, but it does not crash my app:
05-19 02:44:55.580: E/Database(3088): Error inserting
05-19 02:44:55.580: E/Database(3088): android.database.sqlite.SQLiteException: near "null": syntax error: , while compiling: INSERT INTO imagetags(null) VALUES(NULL);
05-19 02:44:55.580: E/Database(3088): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
05-19 02:44:55.580: E/Database(3088): at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:92)
05-19 02:44:55.580: E/Database(3088): at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:65)
05-19 02:44:55.580: E/Database(3088): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:83)
05-19 02:44:55.580: E/Database(3088): at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:41)
05-19 02:44:55.580: E/Database(3088): at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:1231)
05-19 02:44:55.580: E/Database(3088): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1658)
05-19 02:44:55.580: E/Database(3088): at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1515)
05-19 02:44:55.580: E/Database(3088): at com.MyApps.ImageUpdate.ImageDB.tagImage(ImageDB.java:82)
05-19 02:44:55.580: E/Database(3088): at com.MyApps.ImageUpdate.ViewImage.onContextItemSelected(ViewImage.java:134)
05-19 02:44:55.580: E/Database(3088): at android.app.Activity.onMenuItemSelected(Activity.java:2254)
what could i be doing wrong please?.. am i not using the ContentValues correctly enough?
Thank you.
Upvotes: 0
Views: 1338
Reputation: 7
maybe none of the case switches is true in certain case, therefore nothing going to be added in "val".
Upvotes: 0