0

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.

2 Answers 2

1

Could it be that your selection is neither Holidays nor Weather?

Sign up to request clarification or add additional context in comments.

7 Comments

no i doubt its that. there are more options on the context Menu and i get the same error for all of them. am beginning to think some how the Content Values get Lost. but i don't know :(
@Sparrow: I'm pretty sure your ContentValues is empty... Why are you using integral constants instead of R.id.x values?
as you can see, its in a contextMenu and those values(ImageDB.HOLIDAYS and ImageDB.WEATHER) refer to columns in the database which i am trying to put the images in. I don't know whether i should change the tagImage method to take 2 String parameters and then initialize/use the Content Values within the method there?
@sparrow: I was talking about the cases of the switch. Are you manually creating a menu and setting each menu item to the constant Holidays, Weather, etc? Seems like a really bad choice.
Hmmm.. now i remember i was creating it manually before and then i switched to inflating it from an xml menu resource but the cases still refer to Menu.First, Menu.First + 1, Menu.First + 2, because i still wrote them in the same order when i did them manually etc.. hmmm.. could that be the reason? because in the xml menu resource, i am giving it a proper "id".
|
0

maybe none of the case switches is true in certain case, therefore nothing going to be added in "val".

1 Comment

@Hamsi, but am i not calling the method before it returns.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.