【问题标题】:Application did not close cursor or db object was opened here应用程序没有关闭游标或数据库对象在此处打开
【发布时间】:2018-10-06 09:26:34
【问题描述】:

我在我的 android 应用程序中使用 SQLite 数据库。当我进行搜索操作时,我随机发现了这个错误“应用程序没有关闭光标”。这段代码有什么问题吗?这是代码

    field.addTextChangedListener(new TextWatcher() {
                @Override
                public void afterTextChanged(Editable arg0) {

                }

                @Override
                public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {

                }

                @Override
                public void onTextChanged(CharSequence s, int arg1, int arg2, int arg3) {
                    String test = s.toString().trim();
                    if (test.isEmpty()) {
                        if (myCursor != null)
                            myCursor.close();

                        myCursor = getReceipts1Data(orderTypes);
                    myAdapter = new CustomCursorAdapter(activity, myCursor, CursorAdapter.NO_SELECTION);
                    lView.setAdapter(myAdapter);

                    }
                }
            });


 public Cursor getReceipts1Data(Global.OrderType[] orderTypes) 

    {
        String subquery1 = "SELECT ord_id as _id,ord_total,ord_issync,cust_id,isVoid,ord_type" +
                " FROM Orders WHERE ord_type IN (";
        String subquery2 = ") AND isOnHold = '0' ORDER BY rowid DESC";
        Cursor cursor = DBManager.getDatabase().rawQuery(subquery1 + getOrderTypesAsSQLArray(orderTypes) + subquery2, null);
        cursor.moveToFirst();
        return cursor;
    }

【问题讨论】:

    标签: android sqlite cursor


    【解决方案1】:

    如果光标为空,我可以看到关闭光标的那一行,但如果它不为空,我看不到关闭光标的那一行。更具体地说,您是否尝试过添加

    myCursor.close();
    

    行后:

    lView.setAdapter(myAdapter);
    

    在 onTextChanged 方法中

    【讨论】:

      猜你喜欢
      • 2011-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-04
      • 2014-09-21
      • 1970-01-01
      相关资源
      最近更新 更多