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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:06:31+00:00 2026-06-16T06:06:31+00:00

i have an error in my application. I’m new in making apps for android,

  • 0

i have an error in my application.

I’m new in making apps for android, so i don´t now what’s wrong…

this is in the log:

java.lang.IllegalStateException: attempt to re-open an already-closed object: SQLiteQuery: SELECT * FROM pets

i have a SQLite database in which is this method:

public List<Pet> getAllPets() {
    List<Pet> petList = new ArrayList<Pet>();
    String selectQuery = "SELECT * FROM " + TABLE_PETS;

    SQLiteDatabase db = this.getWritableDatabase();
    Cursor cursor = db.rawQuery(selectQuery, null);

    if (cursor.moveToFirst()) {
        do {
            Pet pet = new Pet();
            pet.setID(Integer.parseInt(cursor.getString(0)));
            pet.setName(cursor.getString(1));
            pet.setAge(cursor.getString(2));
            petList.add(pet);
        } while (cursor.moveToNext());
    }
    return petList;     
}

and then i’am using this method from database in other activity to fill the ListView by the names of every pet….

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_list);
    PetListView = (ListView)findViewById(R.id.list);

    MyDatabaseHelper db = new MyDatabaseHelper(this);
    String [] items = new String[db.getPetsCount()];

    List<Pet> pets = db.getAllPets();
    for (int i = 0; i < db.getPetsCount(); i++) {
        items[i] = pets.get(i).getName();                   
    }
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.activity_list_item, items);
    PetListView.setAdapter(adapter);
}

when this activity starts the application crashes down..

Please, can you tell me what’s worng? How can i fix it? Thanks a much for help.

EDIT:

getPetsCount() method:

public int getPetsCount() {
    String countQuery = "SELECT * FROM " + TABLE_PETS;
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.rawQuery(countQuery, null);
    cursor.close();

    return cursor.getCount();
}
  • 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-16T06:06:33+00:00Added an answer on June 16, 2026 at 6:06 am

    i solved this by myself at the end by replace the getPetsCount method:

    public int getPetsCount() {
        String countQuery = "SELECT * FROM " + TABLE_PETS;
        SQLiteDatabase db = this.getReadableDatabase();
        Cursor cursor = db.rawQuery(countQuery, null);
        int count = cursor.getCount();
        cursor.close();
        db.close();
        return count;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, starting with Android and Java, and I have this baffling error: The application
I have this consumer targeted application that has built in error reporting. Sometimes I
In my application I am getting this error: You can only have one <head
i have used impersonation in this application. whenever this error occurs i required to
i have a problem with my Android Application. The Error occures when i want
I have this error and i don't know how to fix it, the master
Okay... I've been wrestling this error for at least an hour now. I have
Using the GitHub application on Mac (not the cli), I have this error which
I have this error controller in my Codeigniter 2.1.0 application: <?php class Error extends
I have the following Codeigniter (MySQL related) error in my application Error Number: 1100

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.