Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6113299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:50:34+00:00 2026-05-23T14:50:34+00:00

For some reason my database is failing to execute a .delete method. I have

  • 0

For some reason my database is failing to execute a .delete method.

I have this check:

if(db.delete(clicked)){
            Log.i("MainAct.class","Deleted row: " + clicked + " successfully");
        } else {
            Log.i("MainAct.class","FAILURE Deleting row: " + clicked + " UNsuccessfully");
        }

It keeps returning “FAILURE” so I figure that means it is not deleting

public boolean delete(String row){
    open();
    Log.i("SmsDatabase.java", "DELETING: " + TABLE_NAME +
            "    id =?    " + "id = '" + row + "'");
     return this.db.delete(TABLE_NAME, "id = '" + row + "'", null) > 0;
}

It is called fine (btw, the open() method has a if(!db.isOpen()) so it doesn’t just always open my database) but it returns false for some reason.

I tried this:

return this.db.delete(TABLE_NAME, “id =?”, new String[]{row}) > 0;

But in the Log it returns weird characters along the line of: “[Lstring@406865” (dont remember exactly) for String clicked. And obviously that is not what I want.

Why is it doing this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:50:35+00:00Added an answer on May 23, 2026 at 2:50 pm

    I’m going to make some assumptions in my answer. (1) The list of whatever you are wanting the user to be able to select for removal is filled with data that was obtained from the database that you are removing it from, (2) You have done the setup in onCreate or something like that to setup the listView’s click listener, or (3) set up the listview to be registered for a Context menu. I suspect that you are just not getting the correct ID for the item to be deleted.

    In my setup I have a listview that has registered for a context menu, I use the context menu to let them select to edit or remove the item from the list so in my onCreate I call registerForContextMenu(this.listView);
    In my context menu I have:

       @Override
       public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo)
       {
          menu.setHeaderTitle("Update Item");
          menu.add(Menu.NONE, MENU_EDIT_ITEM,   0, "Edit Item");
          menu.add(Menu.NONE, MENU_REMOVE_ITEM, 1, "Remove Item");
       }
    

    Then

       @Override
       public boolean onContextItemSelected(MenuItem item)
       {
          return (applyMenuChoice(item) || super.onContextItemSelected(item));
       }
    

    Then

       private boolean applyMenuChoice(MenuItem item)
       {
          AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    
          switch (item.getItemId())
          {
             case MENU_EDIT_ITEM:
             {
                // Since the user wants to edit an existing device we need to pass the
                // database id of the device - not it's position - to the details screen
                long idNum = info.id;
                Intent i = new Intent(getApplicationContext(), DeviceDataActivity.class);
                i.putExtra(DeviceListViewActivity.ID_EXTRA, String.valueOf(idNum));
                startActivityForResult(i, 0);
                break;
             }
             case MENU_REMOVE_ITEM:
             {
                long idNum = info.id;
                deviceDatabaseHelper.deleteItem(String.valueOf(idNum));
                initList();
                break;
             }
             default:
             {
                return false;
             }
          }
          return true;
    
       }// end applyMenuChoice
    

    In my database helper’s code I call the following:

       public void deleteItem(String id)
       {
          SQLiteDatabase db = getWritableDatabase();
          db.delete(TABLE_NAME, _ID + "=?", new String[]
          { id });
          db.close();
       }
    

    Another helpful function to get a particular item. Note if remember to replace Item/YOUR_ITEM with your object and update the query with your table name (YOUR_TABLE) and the BaseColumns._ID as needed.

       /**
        * Use this method to return a single item object based on it's id
        * NOTE - from calling classes id may not be equal to position
        * @param id - the ID of the device being requested
        * @param db - the database to get it from
        * @return YOUR_ITEM - that device associated with the id
        */
       public static YOUR_ITEM getById(String id, SQLiteDatabase db)
       {
          String[] args = { id };
          Cursor c = db.rawQuery( "SELECT * FROM YOUR_TABLE WHERE " + 
                                  BaseColumns._ID + "=?", args );
          c.moveToFirst();
          Item result = new Item().loadFrom(c);
          c.close();
          return (result);
       }
    

    I’m not a very experienced DB guy, so I relied heavily on a lot of the examples out that that had coded a database helper class (extends SQLiteOpenHelper) that facilitated getting and putting data into the SQLiteDataBase. Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(sorry for reposting this question, for some reason I can't log in to the
Having a noob day. For some reason this works: // check for user in
For some reason I never see this done. Is there a reason why not?
For some reason the Windows command prompt is special in that you have to
With some reason my sql database file exploded to become over 88 GB and
I have this Access database that we use to run reports. The report is
for some reason, my xml column in the SQL database is showing squares as
I'm trying to insert text into my SQLite database, but for some reason it
For some reason I have to have a windows client application (written in C#)
I've written some simple functions for database handling like this: function dbOpen($db) { $username

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.