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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:49:58+00:00 2026-06-06T00:49:58+00:00

I am trying to display contents of a SQLite database in android. The code

  • 0

I am trying to display contents of a SQLite database in android. The code works when I don’t add any condition on db2.select. However, it flags an error “close was never called on database” when I add a condition to the query.

What is the solution to this?

Thanks in advance.

Here’s my code:

public class LogDisp extends Activity {
final ResultLog resultlog = new ResultLog(this);
String[] FROM = {_ID,Type,Date,Question,Percent,Avg };
String testtype="Verbal:: Sentence Correction" ;


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //String sqlstr="SELECT Date, Question, Avg, Percent FROM TABLE_NAME2 where Question>5";
    String Orderby= Question+"DESC";

    SQLiteDatabase db2 = resultlog.getReadableDatabase();
    Cursor cursor = db2.query(TABLE_NAME2,FROM,null, null, null, null, Orderby);    

    //Cursor cursor =db2.rawQuery(sqlstr, null); 

    ScrollView sv = new ScrollView(this);
    LinearLayout ll= new LinearLayout(this);
    sv.addView(ll);

    final TableLayout tv = new TableLayout(this);
    ll.addView(tv);
    while(cursor.moveToNext()){
        String type=cursor.getString(1) ;
        String date=cursor.getString(2);
        String question=cursor.getString(3);
        String percent=cursor.getString(4);
        String avg=cursor.getString(5);


        TableRow tr= new TableRow(this);
        tv.addView(tr);
        final String space=""+""+""+""+""+"";
        TextView txtview= new TextView(this);
        txtview.setText(date+space+question+space+percent+space+avg);
        tr.addView(txtview); 
    }

     this.setContentView(sv);
     db2.close();
     cursor.close();

}

}

And here’s my SQLite helper class:

public class ResultLog extends SQLiteOpenHelper{ 
 private static final String DATABASE_NAME2 = "LogofResult.db";
 private static final int DATABASE_VERSION2 = 1;

 public ResultLog(Context ctx) { 
        super(ctx, DATABASE_NAME2, null, DATABASE_VERSION2);
     }  

 // Database creation sql statement
    private static final String DATABASE_CREATE = "create table "
                    + TABLE_NAME2+ "(" + 
                    _ID + " integer primary key autoincrement, " + 
                    Type +" text not null,"+
                    Date     + " integer not null,"+
                    Question + " integer not null,"+  
                    Avg+" real not null,"+
                    Percent +" real not null);" ;


    @Override
    public void onCreate(SQLiteDatabase database) {
                database.execSQL(DATABASE_CREATE);
            }

            @Override
            public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
                db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME2);
                onCreate(db);
            }

        }
  • 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-06T00:50:00+00:00Added an answer on June 6, 2026 at 12:50 am

    close was never called on database

    If it’s called, you need to close your database. You can do it in onDestroy() method or onStop() method.

    And String Orderby= Question+"DESC" this looks like incorrect, add space here

    Question+" DESC" and then it should works. This caused your error.

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

Sidebar

Related Questions

OK folks, I am trying to display the contents of a database table along
I'm trying to display the contents of a textarea, including any line breaks. var
I am trying to display a table in html page. However, the contents of
I am trying to display the contents of a listbox using the SendMessage function.
I am trying to display the contents of a .cpp file in php. I
I'm new to Silverlight and I am trying to display the contents of a
If all I'm trying to do is display the contents of some web page
I am trying to fetch and display contents from table.Currently i am running a
im trying to display content of xmllistcollection in different fields in my datagrid however
I'm trying to display the contents of a text file in a table. I've

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.