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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:33:38+00:00 2026-05-27T23:33:38+00:00

I am using SQLite to store some objects, which are then displayed in a

  • 0

I am using SQLite to store some objects, which are then displayed in a list view. When the activity launches, I simply grab all objects in the db and populate the list view with the results. Occasionally (around 5% of the time), I notice that not all results have returned from the db. I have only ever been shy by 1 result, and, if I reload the activity, the missing result loads properly.

In trying to track down the problem, I logged the Cursor object count post-query and noticed that when a result was missing, it was also missing from the Cursor object (so the problem is not in inflating the returned objects). Does anyone have any experience with this problem?

Below is an example of an object I am storing in my db.

public class MyObject {
    public static final String DB_TABLE = "object";
    public static final int DB_VERSION = 1;

    public static final String COL_ID = "id";
    public static final String COL_TITLE = "title";
    public static final String COL_SUBTITLE = "subtitle";
    public static final String COL_DESCRIPTION = "description";
    public static final String COL_START_TIME = "start_time";
    public static final String COL_END_TIME = "end_time";
    public static final String COL_IMAGE1 = "background_image";
    public static final String COL_IMAGE2 = "icon_image";
    public static final String COL_EXTRAS = "extras";

    public static final String DB_CREATE = String.format("create table if not exists %1$s (%2$s text primary key, %3$s text, %4$s text, %5$s text, %6$s integer, %7$s integer, %8$s text, %9$s text, %10$s integer);", 
        DB_TABLE, COL_ID, COL_TITLE, COL_SUBTITLE, COL_DESCRIPTION, COL_START_TIME, COL_END_TIME, COL_IMAGE1, COL_IMAGE2, COL_EXTRAS);
    public static final String [] DB_COLUMNS = new String [] {COL_ID, COL_TITLE, COL_SUBTITLE, COL_DESCRIPTION, COL_START_TIME, COL_END_TIME, COL_IMAGE1, COL_IMAGE2, COL_EXTRAS};

    public String Id;
    public String Title;
    public String Subtitle;
    public String Description;
    public long StartTime;
    public long EndTime;
    public String Image2;
    public String Image2;
    public int Extras;

    public Event() {}

    public static DataBaseHelper getDBHelper(Context context) {
            return new DataBaseHelper(context, QmobixConferenceApplication.DB_NAME, DB_VERSION, DB_CREATE, DB_TABLE, COL_ID);
    }
}

And the relevant chunks of DataBaseHelper…

public class DataBaseHelper extends SQLiteOpenHelper {  
    private static final String TAG = "DataBaseHelper";

    private SQLiteDatabase mDB;
    private String mSQL;
    private String mDBName;
    private String mTableName;
    private String mKeyId;
    private boolean isClosed = false;

    public DataBaseHelper(Context context, String DBName, int version, String sql, String tableName, String keyId) throws SQLiteException {
        super(context, DBName, null, version);
        this.mSQL = sql;
        this.mDBName = DBName;
        this.mTableName = tableName;
        this.mKeyId = keyId;
        try {
            mDB = this.getWritableDatabase();
            mDB.execSQL(mSQL);
        } catch(SQLiteException ex) {
            Log.e(TAG, String.format("Could not create and/or open the database [ %1$s ]", mDBName), ex);
            throw ex;
        }
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        try {
            db.execSQL(mSQL);
        } catch(SQLException ex) {
            Log.e(TAG, String.format("Could not create table according to SQL [ %1$s }", mSQL), ex);
        }
    }

    @Override
    public synchronized void close() {
        super.close();
        if(mDB != null) {
            mDB.close();
        }
        isClosed = true;
    }

    public Cursor get(String [] columns, String orderBy) {
        return mDB.query(mTableName, columns, null, null, null, null, orderBy);
    }
}

And now for an example loading objects from my db.

    DataBaseHelper db = null;
    Cursor cursor = null;
    try {
        db = MyObject.getDBHelper(mContext);
        cursor = db.get(MyObject.DB_COLUMNS, String.format("%1$s ASC", MyObject.COL_START_TIME));
    } catch(Exception ex) {
        // bad news
    } finally {
        if(cursor != null) { cursor.close(); }
        if(db != null) { db.close(); }
    }

It’s a lot to read through, I know. Hopefully someone has seen this before, and it’s just that I’m doing things a bit off in my DataBaseHelper. I appreciate any suggestions or advice you can offer. Thanks!

  • 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-27T23:33:38+00:00Added an answer on May 27, 2026 at 11:33 pm

    Try to use below code here i am creating list add this list to your listview.

    ArrayList results= new ArrayList();
        SQLiteDatabase myDB = this.openOrCreateDatabase("dummy.db", SQLiteDatabase.OPEN_READWRITE, null);
             try{
                    Cursor c = myDB.rawQuery("select a from xyz", null); 
                    int Column1 = c.getColumnIndex("a");
    
    
                // Check if our result was valid.
                c.moveToFirst();
                if (c != null) {
                    int i = 0;
                    // Loop through all Results
                    do {
                        i++;
                     String a= c.getString(Column1);
    
                     results.add(a);
                        } while (c.moveToNext()); 
                         } 
    
    
                } catch (SQLiteException e) { 
                    e.printStackTrace();
                } finally { 
                     if (myDB != null) 
                          myDB.close(); 
                }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help to store a Object in an SQLite database using Android.I
I am using an sqlite database to store log data. My table has a
I started by trying to store strings in sqlite using python, and got the
Using SQLite I need to copy nearly all of an existing row from a
I'm using SharedPreferences to store some app settings. If I push a new version
So, I am trying to store some data on the SQLite db in Android,
Can somebody please give me some links / tutorials to using SQLite file thatis
I'm attempting to run some unit tests on my application using SQLite in memory,
I'm using SQLite 3.7.2 on Windows. My database is used to store log data
I've managed to store some JSON to a field in my sqlite database, the

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.