我正在尝试在Android中的单元测试中记录并获取这些日志,但我在
中获得了ClassCastExceptionpublic Cursor rawQuery(String sql, String[] selectionArgs,
int initialRead, int maxRead) {
SQLiteCursor c = (SQLiteCursor)rawQueryWithFactory(
null, sql, selectionArgs, null);
c.setLoadStyle(initialRead, maxRead);
return c;
}
这是合乎逻辑的,因为rawQueryWithFactory和其他rawquery方法一样,返回一个CrossProcessCursorWrapper(实现Cursor接口)。
public Cursor rawQueryWithFactory(CursorFactory cursorFactory, String sql, String[] selectionArgs, String editTable) {
//doing stuff
// CrossProcessCursorWrapper implements the Cursor interface as SQLiteCursor but is not of SQLiteCursor type.
return new CrossProcessCursorWrapper(cursor);
}
此代码来自net.sqlcipher.database.SQLiteDatabase(提交:c2aa13e490499482ab38075994cad327d2561749 [c2aa13e])。
更新:
这是我的代码:
dbHelper = new LoggingRecordDBHelper(context, null);
db = dbHelper.getWritableDatabase("pass");
Cursor cursor = db.rawQuery(dbHelper.SQL_LOGGINGRECORD_SELECT_ALL, null);
日志:
运行测试 测试运行开始了 java.lang.ClassCastException:net.sqlcipher.CrossProcessCursorWrapper无法强制转换为net.sqlcipher.database.SQLiteCursor
at net.sqlcipher.database.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1485)
at com.eventmanagement.SQLCipherFetcher.getLogRecords(SQLCipherFetcher.java:31)
at com.eventmanagement.ApplicationTest.testReadLogs(ApplicationTest.java:64)
at java.lang.reflect.Method.invokeNative(Native Method)
在android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
在android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
在android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:554)
在android.app.Instrumentation $ InstrumentationThread.run(Instrumentation.java:1738)
答案 0 :(得分:0)