0

首先要说的是该应用程序运行良好,但是该游标的日志有错误:

public Cursor getDiff() {
        SQLiteDatabase db = this.getReadableDatabase();
        String sacaDif = "SELECT dificultad FROM " + people;
        Cursor c = db.rawQuery(sacaDif, null);
        return c;
    }

我知道这是因为我没有关闭它,但我无法在发送之前或之后关闭光标......

这是日志文件:

05-30 14:48:16.011: D/dalvikvm(363): GC_FOR_MALLOC freed 4814 objects / 256176 bytes in 100ms
05-30 14:48:16.039: E/Cursor(363): Finalizing a Cursor that has not been deactivated or closed. database = /data/data/com.example.proyecto008almacenardatossharedpreferences/databases/administracion, table = null, query = SELECT dificultad FROM dificultad
05-30 14:48:16.039: E/Cursor(363): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
05-30 14:48:16.039: E/Cursor(363):  at android.database.sqlite.SQLiteCursor.<init>(SQLiteCursor.java:210)
05-30 14:48:16.039: E/Cursor(363):  at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:53)
05-30 14:48:16.039: E/Cursor(363):  at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1345)
05-30 14:48:16.039: E/Cursor(363):  at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1315)
05-30 14:48:16.039: E/Cursor(363):  at com.example.proyecto008almacenardatossharedpreferences.CreaTablas.getDiff(CreaTablas.java:47)
05-30 14:48:16.039: E/Cursor(363):  at com.example.proyecto008almacenardatossharedpreferences.Opciones.onCreate(Opciones.java:25)
05-30 14:48:16.039: E/Cursor(363):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-30 14:48:16.039: E/Cursor(363):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-30 14:48:16.039: E/Cursor(363):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-30 14:48:16.039: E/Cursor(363):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-30 14:48:16.039: E/Cursor(363):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-30 14:48:16.039: E/Cursor(363):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-30 14:48:16.039: E/Cursor(363):  at android.os.Looper.loop(Looper.java:123)
05-30 14:48:16.039: E/Cursor(363):  at android.app.ActivityThread.main(ActivityThread.java:4627)
05-30 14:48:16.039: E/Cursor(363):  at java.lang.reflect.Method.invokeNative(Native Method)
05-30 14:48:16.039: E/Cursor(363):  at java.lang.reflect.Method.invoke(Method.java:521)
05-30 14:48:16.039: E/Cursor(363):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-30 14:48:16.039: E/Cursor(363):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-30 14:48:16.039: E/Cursor(363):  at dalvik.system.NativeStart.main(Native Method)

我能做些什么来阻止这个错误?谢谢

4

1 回答 1

1

将数据存储在 pojo 类对象中并返回而不是返回游标。这是一个最佳实践。

于 2013-05-30T15:01:23.537 回答