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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:15:31+00:00 2026-06-14T14:15:31+00:00

I feel like i am missing something simple and stupid. I have a list

  • 0

I feel like i am missing something simple and stupid. I have a list view with a few buttons at the top. The list view is initially populated with data. When you click a button the list view is supposed to populate its self based on a changed variable in the Where statement. In reality i could probably just start a new List activity but i feel like there is a better way.

I have been reading up on CursorAdapter.changeAdapter() and notifydatasetchanged() I have not implemented this yet because i am having a more basic problem.

I can successfully query the database and display the static results in the list. When i try to break process into steps i am running into an ERROR: Invalid statement in fillWindow. The best i understand this is caused by improperly closing cursors databases and DB helpers and for this reason people use content providers.

For now i am just trying to get this to work.

    public class DListView extends ListActivity implements OnClickListener{

public static final String NAME = "Name";

public static final String DESCRIPT = "Description";

public static final String DATABASE_TABLE = "Table";


public static final String DAY = "Day_id";

    /** Called when the activity is first created. */
private Cursor c = null;    

private String[] colsfrom = {"_id", NAME, DESCRIPT, DAY};
private int[] to = new int[] {R.id.text01, R.id.text02, R.id.text03, R.id.text04};

public int b = 0;

public int d = 0; 

   @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.drinklistview);

        View left = findViewById(R.id.left_button);
        left.setOnClickListener(this);
        View right = findViewById(R.id.right_button);
        right.setOnClickListener(this);

        Intent thisIntent = getIntent();
        b = thisIntent.getIntExtra("_b", 0); 
        //0 is the default argument is nothing is passed.
        d = thisIntent.getIntExtra("_d", 0); //same idea as above.

            c = fillList(); 

            /*this creates a new cursor adapter
            @param Context is the list context that you will be filling. 
            @param int layout is the layout that you will use for the rows
            @param Cursor is the cursor that was returned from the query
            @param from is the column names
            @param to is the layout ids that the fields will be put in. 
            @param from is the column names to map from
            @param to is the layout ids that the column fields will be put in. 
            */
            SimpleCursorAdapter myAdapter = new SimpleCursorAdapter(this, R.layout.row, c, colsfrom, to);
            setListAdapter(myAdapter);
   }

private Cursor fillList() {
    DBHelper DbHelper = new DBHelper(this);
    Cursor cursor;
    String wHERE = "_id = " + b + " AND Day_id = " + d ; 

    try {
        myDbHelper.openDataBase();  
    }
    catch(SQLException sqle){
        throw sqle; 
    }

    cursor = myDbHelper.getDrinks(DATABASE_TABLE, colsfrom, wHERE, null, null,null, null);

    myDbHelper.close();

    return cursor;

}

When i put the contents of fillList() in the onCreate() it displays data just fine. When i pull it out it gives me the ERROR. Why is this happening? If anyone has a better way of going about this i would love to read it. Or we can play a game called “What stupid thing am i doing wrong Now?
Thankyou.

EDIT:From DBHelper

public void openDataBase() throws SQLException{

    //Open the database
    String myPath = DB_PATH + DB_NAME;
    myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
}

    @Override
    public synchronized void close() {

        if(myDataBase != null)
            myDataBase.close();
        super.close();
    }

I am thinking that my problem line is the super.close() I believe that this line closes the database and anything affiliated with it which means the cursor that i try to use after its closed. I may be wrong though. Please explain if you can.

  • 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-14T14:15:32+00:00Added an answer on June 14, 2026 at 2:15 pm

    Your problem is right here, in your fillList():

    myDbHelper.close(); // <--- here
    return cursor;
    

    you make a cursor object but close your database connection before you even get to use it (this component of the database) which would render it useless or null if you would. Usually you close the cursor and then the database. But that’s not throwing the error. That error specifically is because you hooked up this cursor to a cursorAdapter trying to fill your listView with nothing. Move that and it should be gone.

    So where do you move it then? If you have a cursor hooked up to listView, it needs to be open the entire time, otherwise you’ll get another error saying “attempting to re-open an already closed object”. I’d suggest putting in the onDestroy() when then listView is being chucked as well.

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

Sidebar

Related Questions

I feel like I'm missing something extremely simple here. So i have the authentication
Okay, I feel like I am missing something really simple here. I have an
I feel like I'm missing something very simple here. I have Eclipse set up
I feel like I am missing something very simple here, but this is the
I feel like I must be missing something simple here... Nothing sends, nor do
I feel like I'm missing something very simple here. I want to play around
Sorry, I'm probably missing something simple here, but I feel like I've tried everything.
I feel like im missing something simple here. I am using the form_for helper
Feel like I'm missing something simple here - When I submit this form it
I feel like I'm missing something simple here (as usual). I'm trying to read

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.