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

  • Home
  • SEARCH
  • 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 8672723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:16:31+00:00 2026-06-12T19:16:31+00:00

I’m new to Java, Android, and SQLite, and I’m stuck at this. I have

  • 0

I’m new to Java, Android, and SQLite, and I’m stuck at this. I have columns, namely _id (autoincrement), type, amount (int), category, and description. Three queries.

Firstly, I am not able to delete a transaction (row) retrieved from database. (Please refer to the attached Logcat).

Secondly, I need to know how to refresh the ListView after deleting the entry.

And third, the silly issue I think. If I open the database once and retrieve data, it does so. Further, without closing the database, if I delete a transaction it does not delete it and gives the error “database not open”. Further, if I close the database after retrieval and then open again at the time of deletion, it works. I dont get it. Main issue is the first one, but please answer if you know any of the above

    final ListView lv = getListView();
    localArrayList.clear();                //To Stop the silly repeating issue
    localDbCrud = new DbCrud(this);
    localAdapter = new SimpleAdapter(
            this,
            localArrayList,
            R.layout.transaction_list_item,
            new String[]{"Amount","Category","Date","Description"},
            new int[]{R.id.tli_amount,R.id.tli_category,R.id.tli_date,R.id.tli_desc});

    localDbCrud.open();
    DbCrud.getAllTransaction();             //Using HashMap localHashMap , localHashMap.put(localArrayList) in loop
    localDbCrud.close();
    lv.setOnItemLongClickListener(new OnItemLongClickListener() {

        public boolean onItemLongClick(final AdapterView<?> arg0, View arg1,
                 final int arg2, final long arg3) {
            // TODO Auto-generated method stub
            AlertDialog.Builder ladbuilder = new Builder(TransactionList.this);
            ladbuilder.setTitle("Choose Your Option");
            ladbuilder.setItems(R.array.alertdialog_prompt, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int selected_item) {
                    // TODO Auto-generated method stub
                    if (selected_item == 0){
                        localDbCrud.open();
                        HashMap itemMap = (HashMap)localAdapter.getItem(arg2);
                        int item_id =(Integer) itemMap.get("Id");
                        DbCrud.deleteTransaction(item_id);
                        //final int ite=  (Integer) arg0.getItemAtPosition(arg2);
                         // final int item_id = c.getInt(c.getColumnIndex(DbCrud.TN_ID));
                        //DbCrud.deleteTransaction(item_id);
                        localDbCrud.close();

                    }
                    else{


                        //update code

                    }
                }
            });
            AlertDialog localad = ladbuilder.create();
            localad.show();


            return false;
        }
    });

    localDbCrud.close();

    setListAdapter(localAdapter);

}

Logcat

10-13 01:21:26.804: E/AndroidRuntime(22023): FATAL EXCEPTION: main
10-13 01:21:26.804: E/AndroidRuntime(22023): java.lang.ClassCastException: java.lang.String
10-13 01:21:26.804: E/AndroidRuntime(22023):    at com.hishighness.budgetracker.TransactionList$1$1.onClick(TransactionList.java:62)
10-13 01:21:26.804: E/AndroidRuntime(22023):    at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:878)
10-13 01:21:26.804: E/AndroidRuntime(22023):    at android.widget.AdapterView.performItemClick(AdapterView.java:284)
10-13 01:21:26.804: E/AndroidRuntime(22023):    at android.widget.ListView.performItemClick(ListView.java:3701)
10-13 01:21:26.804: E/AndroidRuntime(22023):    at android.widget.AbsListView$PerformClick.run(AbsListView.java:1970)
10-13 01:21:26.804: E/AndroidRuntime(22023):    at android.os.Handler.handleCallback(Handler.java:587)
10-13 01:21:26.804: E/AndroidRuntime(22023):    at android.os.Handler.dispatchMessage(Handler.java:92)
10-13 01:21:26.804: E/AndroidRuntime(22023):    at android.os.Looper.loop(Looper.java:130)
    10-13 01:21:26.804: E/AndroidRuntime(22023):    at android.app.ActivityThread.main(ActivityThread.java:3687)
10-13 01:21:26.804: E/AndroidRuntime(22023):    at java.lang.reflect.Method.invokeNative(Native Method)
10-13 01:21:26.804: E/AndroidRuntime(22023):    at java.lang.reflect.Method.invoke(Method.java:507)
10-13 01:21:26.804: E/AndroidRuntime(22023):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
10-13 01:21:26.804: E/AndroidRuntime(22023):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
10-13 01:21:26.804: E/AndroidRuntime(22023):    at dalvik.system.NativeStart.main(Native Method)

here’s the getallTransaction() function.This is the only trace of hash map in my project

    public static void getAllTransaction(){

    Cursor localCursor = localDatabase.query(true, TN_TABLE, null, null, null, null, null, null, null) ;
    if (localCursor != null) {

        localCursor.moveToFirst();
            do{
                HashMap<String,String> temp = new HashMap<String,String>();
                temp.put("Amount", localCursor.getString(localCursor.getColumnIndex("amount")));
                temp.put("Category", localCursor.getString(localCursor.getColumnIndex("category")));
                temp.put("Date", localCursor.getString(localCursor.getColumnIndex("date")));
                temp.put("Description", localCursor.getString(localCursor.getColumnIndex("description")));
                temp.put("Id", localCursor.getString(localCursor.getColumnIndex("_id")));
                TransactionList.localArrayList.add(temp);



            }while (localCursor.moveToNext());

    }
  • 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-06-12T19:16:32+00:00Added an answer on June 12, 2026 at 7:16 pm

    Firstly, I am not able to delete a transaction (row) retrieved from database

    Line 61 is casting the result of arg0.getItemAtPosition(arg2) to Cursor, but the return type is probably HashMap (as it says in the Logcat output). Normally you get a Cursor from a database query.

    If you put the ID for each database row into the HashMap when you’re building it, then you’ll be able to pass that ID to your deleteTransaction() call in your onClick event. So, you need

    temp.put("Id", localCursor.getInt(localCursor.getColumnIndex("_id")));
    

    in getAllTransaction(), and then revise your onClick() method to do something like this:

    localDbCrud.open();
    HashMap itemMap = (HashMap)localAdapter.getItem(arg2);
    int item_id = Integer.parseInt((String)itemMap.get("Id"));
    DbCrud.deleteTransaction(item_id);
    localDbCrud.close();
    

    I would also suggest renaming arg2 (and others) to have clearer names so that the code is easier to follow.

    Secondly, I need to know how to refresh the listview after deleting the entry

    You can call notifyDataSetChanged() on your adapter to refresh the ListView after you’ve made a change to the dataset.

    EDIT: Please note that SimpleAdapter is meant for static data, so your mileage may vary. The best solution is probably to switch to a different type of adapter, such as ArrayAdapter, or make a new SimpleAdapter every time you change the dataset.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have thousands of HTML files to process using Groovy/Java and I need to
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't

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.