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 8546759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:06:33+00:00 2026-06-11T13:06:33+00:00

I have made an app that has 3 activities. In the fisrt activity(Import) i

  • 0

I have made an app that has 3 activities.
In the fisrt activity(Import) i just import some values to a sqlite database.

This is my DatabaseHelper class:

   public class DatabaseHelper_bp extends SQLiteOpenHelper {

    private static final String DATABASE_NAME = "bpDB";
    private static final int DATABASE_VERSION = 1;

    // Database creation sql statement
    private static final String DATABASE_CREATE = "create table bp_import ( _id integer primary key, datetime text not null, systolic text not null, diastolic text not null, pulses text not null, notes text not null);";

    public DatabaseHelper_bp(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    // Method is called during creation of the database
    @Override
    public void onCreate(SQLiteDatabase database) {
        database.execSQL(DATABASE_CREATE);
    }

    // Method is called during an upgrade of the database,
    @Override
    public void onUpgrade(SQLiteDatabase database, int oldVersion,
            int newVersion) {
        Log.w(DatabaseHelper_bp.class.getName(),
                "Upgrading database from version " + oldVersion + " to "
                        + newVersion + ", which will destroy all old data");
        database.execSQL("DROP TABLE IF EXISTS bp_import");
        onCreate(database);
    }
}

And my DAO class for my measures/values:

    public class BpDAO {

    private DatabaseHelper_bp dbHelper;

    private SQLiteDatabase database;
    /**
     * bp table related constants.
     */
    public final static String bp_TABLE = "bp_import";
    public final static String bp_ID = "_id";
    public final static String bp_DT = "datetime";
    public final static String bp_SYS = "systolic";
    public final static String bp_DIA = "diastolic";
    public final static String bp_PUL = "pulses";
    public final static String bp_NOT = "notes";

    /**
     * 
     * @param context
     */
    public BpDAO(Context context) {
        dbHelper = new DatabaseHelper_bp(context);
        database = dbHelper.getWritableDatabase();
    }

    /**
     * \ Creates a new blood pressure measure
     * 
     * @param datetime
     * @param systolic
     * @param diastolic
     * @param pulses
     * @param notes
     * @return
     */
    public long importBP(String datetime, String systolic, String diastolic,
            String pulses, String notes) {
        ContentValues values = new ContentValues();
        values.put(bp_DT, datetime);
        values.put(bp_SYS, systolic);
        values.put(bp_DIA, diastolic);
        values.put(bp_PUL, pulses);
        values.put(bp_NOT, notes);
        return database.insert(bp_TABLE, null, values);
    }

    public void close() {
           database.close();
    }

    /**
     * Fetch all bp
     * 
     * @return
     */
    public Cursor fetchAll_bp() {
        Cursor mCursor = database.query(true, bp_TABLE, new String[] { bp_SYS,
                bp_DIA, bp_DT, bp_ID }, null, null, null, null, null, null);
        if (mCursor != null) {
            mCursor.moveToFirst();
        }
        return mCursor;
    }
}

In the second activity(History) i have a List that is populated by the database,all okenter image description here

Here is the code of 2 Activity(history):

public class HistoryActivity extends ListActivity {

private BpDAO dao;

private SimpleCursorAdapter dbAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    dao = new BpDAO(this);
    Cursor bpList = dao.fetchAll_bp();
    String[] from = new String[] { BpDAO.bp_SYS, BpDAO.bp_DIA, BpDAO.bp_DT };
    int[] target = new int[] { R.id.bpSysHolder, R.id.bpDiaHolder,
            R.id.bpDtHolder };
    dbAdapter = new SimpleCursorAdapter(this, R.layout.history_bp, bpList,
            from, target);
    setListAdapter(dbAdapter);
}

@Override
public void onListItemClick(ListView l, View view, int position, long id) {
    // TODO Auto-generated method stub
    super.onListItemClick(l, view, position, id);
    Log.d("BPT", "Selected bp id =" + id);
            // log says that i have selected an item with id : 11 

    Cursor selectedBpDetails = (Cursor) l.getItemAtPosition(position);

    String bp_DT = selectedBpDetails.getString(selectedBpDetails
            .getColumnIndex(BpDAO.bp_DT));
    String bp_SYS = selectedBpDetails.getString(selectedBpDetails
            .getColumnIndex(BpDAO.bp_SYS));
    String bp_DIA = selectedBpDetails.getString(selectedBpDetails
            .getColumnIndex(BpDAO.bp_DIA));
    String bp_PUL = selectedBpDetails.getString(selectedBpDetails
            .getColumnIndex(BpDAO.bp_PUL));
    String bp_NOT = selectedBpDetails.getString(selectedBpDetails
            .getColumnIndex(BpDAO.bp_NOT));

    Log.d("BPT", "Selected bp details = { date=" + bp_DT + ", systolic="
            + bp_SYS + ", diastolic=" + bp_DIA + ", pulses=" + bp_PUL
            + ", notes=" + bp_NOT + " }");

    Intent intent = new Intent(HistoryActivity.this, FromHistory.class);
    intent.putExtra("bp_SYS", bp_SYS);
    intent.putExtra("bp_DIA", bp_DIA);
    intent.putExtra("bp_DT", bp_DT);
    intent.putExtra("bp_PUL", bp_PUL);
    intent.putExtra("bp_NOT", bp_NOT);
    startActivity(intent);
}

}

When i click on a list item i start a new activity that i show all the infos of the measure from the database.

But i have in logcat:

1.close() was never explicitly called on database
2.android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
3.E/System(561): java.lang.IllegalStateException: Don't have database lock!

I have seen some other questions but didn’t manage to find how to close it for my situation.

  • 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-11T13:06:34+00:00Added an answer on June 11, 2026 at 1:06 pm

    (You should close your Cursors when you are done with them as the others have pointed out, but…)
    The error is telling you that you need to close your SQLiteDatabase. Add this method to your BpDAO class:

    public void close() {
        database.close();
    }
    

    And whenever you create a new BpDAO object in any Activity you need to call close(), you can do this as soon as you are done or in onDestroy():

    @Override
    protected void onDestroy() {
        super.onDestroy();
        dao.close();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made an Android app that has an external database, using WAMP and
With the help of this tutorial i have made an app that has 3
I have made an app that has got a lot of graphics for a
i have made an app that would calculate numbers from input fields. **main Activity
I have made a Azure web app that has a ASP.NET web that also
I have made an app that has a permission for use of the vibrator.
I have made an app that gets an array of addresses from a web
I have made an app that implements the iPhone's camera. When the user finishes
I have a django app that I made and have implemented a plist into
I have a new app that I made and put in the store yesterday.

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.