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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:05:24+00:00 2026-06-13T05:05:24+00:00

I have once again problems concerning a ListView which is populated by a database.

  • 0

I have once again problems concerning a ListView which is populated by a database. I’m trying to make an OnClickListener for the database and it seems to be correct to me, however the code produces an illegal state exception.

Code:

private void getData() {
    db.open();
    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, 
            android.R.layout.simple_list_item_1, 
            db.getAllSubjects(), 
            new String[] { "subject" }, 
            new int[] { android.R.id.text1 });

    ListView listView = (ListView) findViewById(android.R.id.list);
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long id)
        {
        Cursor cursor = db.getSubject(id);
        String subject = null;
        try {
            subject = cursor.getString(cursor.getColumnIndex("subject"));
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Intent intent = new Intent(Main.this, Marks.class);
        intent.putExtra("selected", subject);
        startActivity(intent);
        db.close();
        }
    });
}

LogCat:

10-15 15:41:10.674: E/AndroidRuntime(23675): FATAL EXCEPTION: main
10-15 15:41:10.674: E/AndroidRuntime(23675): java.lang.IllegalStateException: database /data/data/maturaarbeit.nicola_pfister.marks/databases/database (conn# 0) already closed
10-15 15:41:10.674: E/AndroidRuntime(23675):    at android.database.sqlite.SQLiteDatabase.verifyDbIsOpen(SQLiteDatabase.java:2082)
10-15 15:41:10.674: E/AndroidRuntime(23675):    at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1445)
10-15 15:41:10.674: E/AndroidRuntime(23675):    at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1405)
10-15 15:41:10.674: E/AndroidRuntime(23675):    at maturaarbeit.nicola_pfister.marks.database.DBAdapter.getSubject(DBAdapter.java:137)
10-15 15:41:10.674: E/AndroidRuntime(23675):    at maturaarbeit.nicola_pfister.marks.Main$1.onItemClick(Main.java:59)
10-15 15:41:10.674: E/AndroidRuntime(23675):    at android.widget.AdapterView.performItemClick(AdapterView.java:292)
10-15 15:41:10.674: E/AndroidRuntime(23675):    at android.widget.AbsListView.performItemClick(AbsListView.java:1058)
10-15 15:41:10.674: E/AndroidRuntime(23675):    at android.widget.AbsListView$PerformClick.run(AbsListView.java:2514)
10-15 15:41:10.674: E/AndroidRuntime(23675):    at android.widget.AbsListView$1.run(AbsListView.java:3168)
10-15 15:41:10.674: E/AndroidRuntime(23675):    at android.os.Handler.handleCallback(Handler.java:605)
10-15 15:41:10.674: E/AndroidRuntime(23675):    at android.os.Handler.dispatchMessage(Handler.java:92)
10-15 15:41:10.674: E/AndroidRuntime(23675):    at android.os.Looper.loop(Looper.java:137)
10-15 15:41:10.674: E/AndroidRuntime(23675):    at android.app.ActivityThread.main(ActivityThread.java:4424)
10-15 15:41:10.674: E/AndroidRuntime(23675):    at java.lang.reflect.Method.invokeNative(Native Method)
10-15 15:41:10.674: E/AndroidRuntime(23675):    at java.lang.reflect.Method.invoke(Method.java:511)
10-15 15:41:10.674: E/AndroidRuntime(23675):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-15 15:41:10.674: E/AndroidRuntime(23675):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-15 15:41:10.674: E/AndroidRuntime(23675):    at dalvik.system.NativeStart.main(Native Method)

Thanks for your help!

  • 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-13T05:05:25+00:00Added an answer on June 13, 2026 at 5:05 am

    That’s because you do close you database in onItemClick. So, when you click the second time onItemClick gets called again but the database has already been closed.

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

Sidebar

Related Questions

I have once again fleshed out Ruby, after two years of not touching it,
Once again a question about the garbage collector in actionscript-3: If I have a
I'm having problems trying to use the friend feature of C++. I have these
I seem to have two problems 1) While trying to update my singular nested
I am currently trying to improve on an Access Database VBA that I have
I once have noticied when my Adobe Reader was updating, I saw a small
I have a click-once deployed app that uses a notification icon created using the
I have a load once jqgrid that uses a custom formatter to display checkboxes
Once you have your first set of requirements and design done where do you
Once you have uploaded your source code to Heroku, is it possible to download

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.