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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:01:12+00:00 2026-06-01T13:01:12+00:00

When I use below code query database, I cannot get any result, but I

  • 0

When I use below code query database, I cannot get any result, but I can get results via sql command on console.

DBHelper dbHelper = new DBHelper(SampleActivity.this, "contents.db", null, 1);
SQLiteDatabase db = dbHelper.getWritableDatabase();
//Cursor cursor = db.query("ContentsTable", new String[] { "title" }, "id<10", null, null, null, null);
Cursor cursor = db.rawQuery("select title from ContentsTable", null);
db.close();
cursor.close();

I debug the program and found cursor’s mCount=-1, and mStackTrace=DatabaseObjectNotClosedException after running db.rawquery(*), just like the photo showed:http://flic.kr/p/bw9P2o

Below is class DBHelper:
public class DBHelper extends SQLiteOpenHelper{

    public DBHelper(Context context, String name, CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        String createTable = "create table ContentsTable(id int, title varchar(100))";
        db.execSQL(createTable);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        System.out.println("Update Database");
    }

}
  • 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-01T13:01:13+00:00Added an answer on June 1, 2026 at 1:01 pm

    Forgive the simple question but have you added rows yet?

    EDIT:

    You have to call cursor.moveToFirst() before accessing the data returned.

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

Sidebar

Related Questions

I use the below code to write code to query a web method in
How to Remove Badge from the tabbar item i had use below code but
Normally I use the below code, but is there a better way? lastOfMonth =
When I try to use the code below I get a duplicate variable error
I'm trying to use the code below to send messages via System.Net.Mail and am
Can anyone help me to rewrite the below code which use a fade effect
The code listed below attempts to update a row in the database, but throws
The code below should print ten results but instead it prints ten test-ite. Why
How can I edit the code I use below to save the generated file
how do i get the array value from below code?. and use while loop

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.