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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:11:56+00:00 2026-05-26T09:11:56+00:00

I have a problem understanding why is my ListActivity and its corresponding listView empty

  • 0

I have a problem understanding why is my ListActivity and its corresponding listView empty when I call close() method on cursor object?

Let me explain myself a bit…

I retreive some values from a DB and get the result in my cursor object. After that I create my SimpleCursorAdapter and bind column from db with a field in my listView.

Works like a charm, but…

If I call cursor.close() at the end of onCreate() method my listView is shown empty?

If I log the values from cursor to LogCat they’re there until calling cursor.close() and that makes perfect sense, but why is the listAdapter emptied when cursor.close() is called???
I would expect ListAdapter listAdapter = new SimpleCursorAdapter(…) to hold the values that are “binded” to a listView until we activity is destroyed…

Why is this so? When and why is necessary to close cursor?

public class ListTrainingsView extends ListActivity{
private SQLiteDatabase db;
private ListAdapter  listAdapter;
private Cursor cursor;

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.list_trainings);

    DatabaseHelper helper = new DatabaseHelper(this);

    this.db = helper.getWritableDatabase();

    this.cursor = db.query("trainings", fields, null, null, null, null, null);

    startManagingCursor(cursor);

    this.listAdapter = new SimpleCursorAdapter(this,
            R.layout.list_trainings_item, 
            cursor, 
            new String[] {"name"},
            new int[] { R.id.name_entry}
    );

    this.setListAdapter(this.listAdapter);

//If I call 
//cursor.close();
//shown list is empty

Another question is more of basic Java language type of question… I come from PHP OO background and there if you define member variable you have to work with it in object methods using syntax $this->cursor. I’ve noticed that in Android/Java I don’t have to use this.cursor.getCount() to get the reference/value from it. It’s enough to say cursor.getCount() How come this is allowed?

  • 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-26T09:11:57+00:00Added an answer on May 26, 2026 at 9:11 am

    Why is this so?

    Adapter needs data from provided Cursor and prepare ListView accordingly, and when you call cursor.close() the Cursor is released and made invalid. (means there is no data.)

    When and why is necessary to close cursor?

    It is necessary to close the Cursor while you are about to leave the Activity and going back from the Activity otherwise Cursor got leaked for that Activity.

    • References From documentation
    • Any why it is necessary

    It’s enough to say cursor.getCount() How come this is allowed?

    The structure of Java is based on classes. Every action is done within a specific class. Even echoing “single line” would need a class. and when you are in a class you can access class members with this OR with direct their variables

    • For more see here
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem understanding how the parameter passed to the drawInRect method is
I have a problem understanding how the try{} catch(Exception e){...} works! Let's say I
I seem to have a problem understanding how to conditionally test a boolean value
I think I have a problem in understanding the proper way of using MVC.
I have an understanding problem of how the following code works: XMLInputFactory xif =
There are many skills a programmer could have (understanding the problem, asking good questions,
I am facing a situation that I have problem understanding... I am writing a
I have a problem understanding why a certain implicit conversion is not working as
I have a problem understanding why shared_ptr is using atomic cpu instructions... I cant
I have a problem understanding what's causes the compilation error in the code below:

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.