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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:29:47+00:00 2026-06-05T04:29:47+00:00

I have a SQLite db, an it works, but I get following error at

  • 0

I have a SQLite db, an it works, but I get following error at the Logcat on change or add contend. Were do I have to close the db?

06-08 12:52:29.897: E/Database(6274): close() was never explicitly called on database '/data/data/de.android.test/databases/table.db' 
06-08 12:52:29.897: E/Database(6274): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
06-08 12:52:29.897: E/Database(6274):   at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1900)
06-08 12:52:29.897: E/Database(6274):   at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:884)
06-08 12:52:29.897: E/Database(6274):   at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:918)
06-08 12:52:29.897: E/Database(6274):   at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:911)
06-08 12:52:29.897: E/Database(6274):   at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:548)
06-08 12:52:29.897: E/Database(6274):   at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:203)
06-08 12:52:29.897: E/Database(6274):   at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:98)
06-08 12:52:29.897: E/Database(6274):   at de.database.DAO.<init>(DAO.java:39)
06-08 12:52:29.897: E/Database(6274):   at de.AWocheActivity.onClick(AWocheActivity.java:551)
06-08 12:52:29.897: E/Database(6274):   at android.view.View.performClick(View.java:2408)
06-08 12:52:29.897: E/Database(6274):   at android.view.View$PerformClick.run(View.java:8817)
06-08 12:52:29.897: E/Database(6274):   at android.os.Handler.handleCallback(Handler.java:587)
06-08 12:52:29.897: E/Database(6274):   at android.os.Handler.dispatchMessage(Handler.java:92)
06-08 12:52:29.897: E/Database(6274):   at android.os.Looper.loop(Looper.java:144)
06-08 12:52:29.897: E/Database(6274):   at android.app.ActivityThread.main(ActivityThread.java:4937)
06-08 12:52:29.897: E/Database(6274):   at java.lang.reflect.Method.invokeNative(Native Method)
06-08 12:52:29.897: E/Database(6274):   at java.lang.reflect.Method.invoke(Method.java:521)
06-08 12:52:29.897: E/Database(6274):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
06-08 12:52:29.897: E/Database(6274):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
06-08 12:52:29.897: E/Database(6274):   at dalvik.system.NativeStart.main(Native Method)

This is the code:

Activity:

     public void onCreate(Bundle savedInstanceState) {
    .
    .
    .
    dao = new DAO(this);
    Cursor subjectList = dao.fetchAllSubject();
   }

    public void onClick(View v) {
    global_db_Id = 0;

    dao = new DAO(this);
    Cursor subjectList = dao.fetchAllSubject();

        if (global_db_Id == 0){
        long insertedId = dao.createSubject(String.valueOf(hour), "A", String.valueOf(day), fach_kurz.getText().toString(), fach_lang.getText().toString(), String.valueOf(item), room.getText().toString(),String.valueOf(index_awoche));
        }else{
            dao.updateSubject(String.valueOf(global_db_Id), String.valueOf(hour), "A", String.valueOf(day), fach_kurz.getText().toString(), fach_lang.getText().toString(), String.valueOf(item), room.getText().toString(), String.valueOf(index_awoche));

         //if (dao != null) {
         //dao.close();
        //}         
}

On the end of the onClick Method I tried to close the database, but then the app crashes compleatly.
Database:

    public class DAO {

        private DatabaseHelper dbHelper;

        private SQLiteDatabase database;
        public long createSubject(String hour, String week, String day, String name,String desc, String col, String room, String btn_nr){
            ContentValues values = new ContentValues();
            values.put(COLUMN_HOUR, hour);
            values.put(COLUMN_WEEK, week);
            values.put(COLUMN_DAY, day);
            values.put(COLUMN_NAME, name);
            values.put(COLUMN_DESCRIPTION, desc);
            values.put(COLUMN_COLOUR, col);
            values.put(COLUMN_ROOM, room);
            values.put(COLUMN_BTN_NR, btn_nr);



return database.insert(TABLE, null, values);
    }

    public Cursor fetchAllSubject(){
        Cursor mCursor = database.query(true, TABLE, new String[] {
                COLUMN_ID, COLUMN_HOUR, COLUMN_WEEK, COLUMN_DAY, COLUMN_NAME, COLUMN_DESCRIPTION, COLUMN_COLOUR, COLUMN_ROOM, COLUMN_BTN_NR},null
                , null, null, null, null, null);
        if (mCursor != null) {
            mCursor.moveToFirst();
        }
        return mCursor;
    }

    public int updateSubject(String id, String hour, String week, String day, String name,String desc, String col, String room, String btn_nr){
        ContentValues values = new ContentValues();
        values.put(COLUMN_HOUR, hour);
        values.put(COLUMN_WEEK, week);
        values.put(COLUMN_DAY, day);
        values.put(COLUMN_NAME, name);
        values.put(COLUMN_DESCRIPTION, desc);
        values.put(COLUMN_COLOUR, col);
        values.put(COLUMN_ROOM, room);
        values.put(COLUMN_BTN_NR, btn_nr);
        return database.update(TABLE, values,COLUMN_ID + "=?",new String[]{id});
        }
    // This I tried on the end of the onClick Method    
    public void close(){
            if(database!=null)
                database.close();
    }
  • 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-05T04:29:49+00:00Added an answer on June 5, 2026 at 4:29 am

    Write the below code in your database file

    public class DataBaseHelper extends SQLiteOpenHelper {
    
       public DataBaseHelper(Context context) {
    
        super(context, DB_NAME, null, 1);
        this.myContext = context;
     }
    
    
        @Override
        public synchronized void close() {
    
        if (myDataBase != null)
            myDataBase.close();
    
        super.close();
    
        }
    
        @Override
        public void onCreate(SQLiteDatabase arg0) {
    
        }
    
        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    
        }
    

    and then call from activity

     myDataBase.close();
    

    This is good link to refer

    http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/

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

Sidebar

Related Questions

I have the following named_scope which works fine in MySQL and sqlite but bombs
I have the following command which works fine on Linux Console. But to get
I have the following models but I cannot get the custom method reorder_action_items to
I have everything installed. But when I run rake db:create, I get the following:
I have an app pulling information from a SQLite database. It works perfectly on
I am using the SQLite database and have the following persistent class (simplified): public
I'm using DBI to query a SQLite3 database. What I have works, but it
I have a sqlite syntax error. What is incorrect? my code: + (void)insertUpdateCatalogTime:(NSString *)time
I have a SQLite database that is used by two processes. I am wondering,
I have a SQLite database that contains a huge set of log messages. I

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.