2012-11-21 39 views
1

下面我發佈logcat詳細信息。請告訴我如何解決這個問題。IllegalStateException:SQLite光標已關閉

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 [email protected] 
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 [email protected] 
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 

我的Java代碼:

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(); 



     } 
    } 
+1

請顯示您的java代碼 –

+0

問題是,當我按Back按鈕應用程序關閉。當我按下「後退」按鈕時,我應該怎麼做,我必須進行上一個活動。 – Abhay

+0

你有沒有相同的解決方案? –

回答

0

第一:你應該閱讀StackOverflow上的常見問題。

二:通過閱讀你的logcat我的理解是:

java.lang.RuntimeException: Unable to resume activity {com.example.shaktitool/com.example.shaktitool.Product}: java.lang.IllegalStateException: trying to requery an already closed cursor [email protected] 

Caused by: java.lang.IllegalStateException: trying to requery an already closed cursor [email protected] 

所以:trying to requery an already closed cursor意味着你做錯事的SQLite。發佈你的Java代碼,你會得到幫助。

+0

Downvote for? 「遊標」只是簡單的關閉。 – shkschneider

0

試圖重新查詢一個已經關閉的遊標[email protected]

您試圖訪問一個已經關閉的遊標。

如果您仍然需要它,或者創建新的數據庫查詢以獲取另一個,請不要關閉遊標。

0

錯誤很明顯。

java.lang.IllegalStateException:試圖重新查詢已經關閉的 遊標。

很難說清楚你是如何排隊你已經關閉的光標的。 但有一種猜測是你可能正在使用startManagingCursor()並傳遞它已關閉的遊標。