1

Below I am posting the logcat details. Please tell me How to resolve that.

11-21 14:49:33.604: E/AndroidRuntime(1721): FATAL EXCEPTION: main
11-21 14:49:33.604: E/AndroidRuntime(1721): java.lang.RuntimeException: Unable to resume activity {com.example.shaktitool/com.example.shaktitool.Product}: java.lang.IllegalStateException: trying to requery an already closed cursor  android.database.sqlite.SQLiteCursor@41334490
11-21 14:49:33.604: E/AndroidRuntime(1721):     at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2575)
11-21 14:49:33.604: E/AndroidRuntime(1721):     at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2603)
11-21 14:49:33.604: E/AndroidRuntime(1721):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
11-21 14:49:33.604: E/AndroidRuntime(1721):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-21 14:49:33.604: E/AndroidRuntime(1721):     at android.os.Looper.loop(Looper.java:137)
11-21 14:49:33.604: E/AndroidRuntime(1721):     at android.app.ActivityThread.main(ActivityThread.java:4745)
11-21 14:49:33.604: E/AndroidRuntime(1721):     at java.lang.reflect.Method.invokeNative(Native Method)
11-21 14:49:33.604: E/AndroidRuntime(1721):     at java.lang.reflect.Method.invoke(Method.java:511)
11-21 14:49:33.604: E/AndroidRuntime(1721):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-21 14:49:33.604: E/AndroidRuntime(1721):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-21 14:49:33.604: E/AndroidRuntime(1721):     at dalvik.system.NativeStart.main(Native Method)
11-21 14:49:33.604: E/AndroidRuntime(1721): Caused by: java.lang.IllegalStateException: trying to requery an already closed cursor  android.database.sqlite.SQLiteCursor@41334490
11-21 14:49:33.604: E/AndroidRuntime(1721):     at android.app.Activity.performRestart(Activity.java:5051)
11-21 14:49:33.604: E/AndroidRuntime(1721):     at android.app.Activity.performResume(Activity.java:5074)
11-21 14:49:33.604: E/AndroidRuntime(1721):     at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2565)
11-21 14:49:33.604: E/AndroidRuntime(1721):     ... 10 more

My Java Code:

package com.example.shaktitool;
    import android.app.Activity;
    import android.content.Intent;
    import android.database.Cursor;
    import android.os.Bundle;
    import android.view.KeyEvent;
    import android.view.View;
    import android.widget.AdapterView;
    import android.widget.AdapterView.OnItemClickListener;
    import android.widget.ListView;
    import android.widget.SimpleCursorAdapter;



    public class Product extends Activity {

    protected static final String PRODUCT_REQUEST = null;

    private SQLiteAdapterPro mySQLiteAdapter;

        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.product);

            Intent intent = getIntent();

            ListView list = (ListView)findViewById(R.id.content_list);


            /*
             *  Create/Open a SQLite database
             *  and fill with dummy content
             *  and close it
             */
            mySQLiteAdapter = new SQLiteAdapterPro(this);
            mySQLiteAdapter.openToWrite();
            mySQLiteAdapter.deleteAll();

            mySQLiteAdapter.insert("ELECTRONICS-COMPUTERS");
            mySQLiteAdapter.insert("DESKTOPS");
            mySQLiteAdapter.insert("NOTEBOOKS");

            mySQLiteAdapter.close();

            /*
             *  Open the same SQLite database
             *  and read all it's content.
             */
            mySQLiteAdapter = new SQLiteAdapterPro(this);
            mySQLiteAdapter.openToRead();

            Cursor cursor = mySQLiteAdapter.queueAll();
            startManagingCursor(cursor);

            String[] from = new String[]{SQLiteAdapter.KEY_CONTENT};
            int[] to = new int[]{R.id.text};

            SimpleCursorAdapter cursorAdapter =
                new SimpleCursorAdapter(this, R.layout.row, cursor, from, to);

            list.setAdapter(cursorAdapter);

            list.setOnItemClickListener( new OnItemClickListener() {

                public void onItemClick(AdapterView<?> arg0, View arg1,
                        int position, long arg3) {

                    switch(position){

                    case 1 : Intent intent = new Intent(Product.this, Desktop.class);
                             startActivity(intent);

                             break;

                    case 2 : Intent intent1 = new Intent(Product.this, Notebook.class);
                             startActivity(intent1);

                             break;                        


                    }
                }   
            });


            mySQLiteAdapter.close();



        }
    }
4

3 回答 3

0

trying to requery an already closed cursor android.database.sqlite.SQLiteCursor@41334490

You are trying to access a Cursor that is already closed.

Don't close the cursor if you still need it or make a new DB query to get another one.

于 2012-11-21T10:09:51.903 回答
0

The error is clear.

java.lang.IllegalStateException: trying to requery an already closed cursor.

Its hard to tell how you are queuing the cursor which you have already closed. But one guess is you may be using startManagingCursor() and passing it already closed cursor.

于 2012-11-21T10:12:30.540 回答
-1

First: your should read the FAQ of StackOverflow.

Second: by reading your logcat I understand that:

java.lang.RuntimeException: Unable to resume activity {com.example.shaktitool/com.example.shaktitool.Product}: java.lang.IllegalStateException: trying to requery an already closed cursor  android.database.sqlite.SQLiteCursor@41334490

Caused by: java.lang.IllegalStateException: trying to requery an already closed cursor  android.database.sqlite.SQLiteCursor@41334490

So: trying to requery an already closed cursor means that you do something wrong with SQLite. Post your java code and you'll get help.

于 2012-11-21T10:09:50.360 回答