Android 安卓&x2B;Robolectric-ContentProvider中queryBuilder.query()中的RuntimeException/InstanceionException

Android 安卓&x2B;Robolectric-ContentProvider中queryBuilder.query()中的RuntimeException/InstanceionException,android,sqlite,junit,instantiation,robolectric,Android,Sqlite,Junit,Instantiation,Robolectric,我对只使用SQLite的ContentProvider进行了大约十次测试;all pass保存内容提供程序的query()方法中通过queryBuilder.query()的两个 正在测试的方法在实际应用中有效 这适用于API 17 r2和RoboLectric: robolectric-2.0-alpha-3-20130417.013705-46-jar-with-dependencies.jar @Override public Cursor query(Uri uri, String[]

我对只使用SQLite的ContentProvider进行了大约十次测试;all pass保存内容提供程序的query()方法中通过queryBuilder.query()的两个

正在测试的方法在实际应用中有效

这适用于API 17 r2和RoboLectric: robolectric-2.0-alpha-3-20130417.013705-46-jar-with-dependencies.jar

@Override
public Cursor query(Uri uri, String[] projection, String selection,
        String[] selectionArgs, String sortOrder) {
    Log.d(Constants.TAG, "MyContentProvider.query()");
    switch(matcher.match(uri)) {
    case ITEM: // OK
        selection = "_id = ?";
        selectionArgs = new String[]{ Long.toString(ContentUris.parseId(uri)) };
    case ITEMS: // OK
        break;
    default:
        throw new IllegalArgumentException("Did not recognize URI " + uri);
    }
    // build the query with SQLiteQueryBuilder
    SQLiteQueryBuilder qBuilder = new SQLiteQueryBuilder();
    qBuilder.setTables(TABLE_NAME);

    // query the database and get result in cursor
    final SQLiteDatabase db = mDatabase.getReadableDatabase();
    Cursor resultCursor = qBuilder.query(db,    // Line 112 in trace
            projection, selection, selectionArgs, null, null, sortOrder,
            null);
    resultCursor.setNotificationUri(getContext().getContentResolver(), uri);
    return resultCursor;
}
以下是回溯:

java.lang.RuntimeException: java.lang.InstantiationException
    at org.robolectric.bytecode.ShadowWrangler.createShadowFor(ShadowWrangler.java:300)
    at org.robolectric.bytecode.ShadowWrangler.initializing(ShadowWrangler.java:74)
    at org.robolectric.bytecode.RobolectricInternals.initializing(RobolectricInternals.java:90)
    at android.database.sqlite.SQLiteQuery.$$robo$init(SQLiteQuery.java)
    at android.database.sqlite.SQLiteClosable.<init>(SQLiteClosable.java:26)
    at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:41)
    at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
    at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
    at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314)
    at android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java:400)
    at android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java:333)
    at com.example.readingsprovider.ReadingsContentProvider.query(ReadingsContentProvider.java:112)
    at com.example.readingsprovider.test.ContentProviderTest.testUpdateMultipleWithoutWhere(ContentProviderTest.java:110)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:267)
    at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:202)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.InstantiationException
    at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:30)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at java.lang.Class.newInstance0(Class.java:357)
    at java.lang.Class.newInstance(Class.java:310)
    at org.robolectric.bytecode.ShadowWrangler.createShadowFor(ShadowWrangler.java:293)
    at org.robolectric.bytecode.ShadowWrangler.initializing(ShadowWrangler.java:74)
    at org.robolectric.bytecode.RobolectricInternals.initializing(RobolectricInternals.java:90)
    at android.database.sqlite.SQLiteQuery.$$robo$init(SQLiteQuery.java)
    at android.database.sqlite.SQLiteClosable.<init>(SQLiteClosable.java:26)
    at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:41)
    at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
    at android.database.sqlite.SQLiteDirectCursorDriver.$$robo$$SQLiteDirectCursorDriver_7ac1_query(SQLiteDirectCursorDriver.java:44)
    at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java)
    at android.database.sqlite.SQLiteDatabase.$$robo$$SQLiteDatabase_ab15_rawQueryWithFactory(SQLiteDatabase.java:1314)
    at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java)
    at android.database.sqlite.SQLiteQueryBuilder.$$robo$$SQLiteQueryBuilder_ba4d_query(SQLiteQueryBuilder.java:400)
    at android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java)
    at android.database.sqlite.SQLiteQueryBuilder.$$robo$$SQLiteQueryBuilder_ba4d_query(SQLiteQueryBuilder.java:333)
    at android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java)
    at com.example.readingsprovider.ReadingsContentProvider.query(ReadingsContentProvider.java:112)
    at com.example.readingsprovider.test.ContentProviderTest.testUpdateMultipleWithoutWhere(ContentProviderTest.java:110)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    ... 21 more
java.lang.RuntimeException:java.lang.InstanceionException
位于org.roblectric.bytecode.ShadowWrangler.createShadowFor(ShadowWrangler.java:300)
位于org.roblectric.bytecode.ShadowWrangler.initialization(ShadowWrangler.java:74)
位于org.roblectric.bytecode.roblectricinternals.initialization(roblectricinternals.java:90)
位于android.database.sqlite.SQLiteQuery.$$robo$init(SQLiteQuery.java)
位于android.database.sqlite.SQLiteClosable.(SQLiteClosable.java:26)
位于android.database.sqlite.SQLiteProgram.(SQLiteProgram.java:41)
位于android.database.sqlite.SQLiteQuery(SQLiteQuery.java:37)
位于android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
位于android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314)
位于android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java:400)
位于android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java:333)
位于com.example.readingsprovider.readingContentProvider.query(readingContentProvider.java:112)
在com.example.readingsprovider.test.ContentProviderTest.TestUpdateMultiplewithout此处(ContentProviderTest.java:110)
位于org.junit.runners.model.FrameworkMethod$1.runReflectVeCall(FrameworkMethod.java:44)
位于org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
位于org.junit.runners.model.FrameworkMethod.invokeeexplosive(FrameworkMethod.java:41)
位于org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
位于org.roblectric.roblectrictTestRunner$2.evaluate(roblectrictTestRunner.java:267)
位于org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
位于org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
位于org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
位于org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
位于org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
位于org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
访问org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
位于org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
位于org.roblectric.roblectrictTestRunner$1.evaluate(roblectrictTestRunner.java:202)
位于org.junit.runners.ParentRunner.run(ParentRunner.java:236)
位于org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
位于org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
位于org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
位于org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
位于org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
位于org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
原因:java.lang.InstanceionException
位于sun.reflect.InstanceExceptionConstructorAccessorImpl.newInstance(InstanceExceptionConstructorAccessorImpl.java:30)
位于java.lang.reflect.Constructor.newInstance(Constructor.java:513)
位于java.lang.Class.newInstance0(Class.java:357)
位于java.lang.Class.newInstance(Class.java:310)
位于org.roblectric.bytecode.ShadowWrangler.createShadowFor(ShadowWrangler.java:293)
位于org.roblectric.bytecode.ShadowWrangler.initialization(ShadowWrangler.java:74)
位于org.roblectric.bytecode.roblectricinternals.initialization(roblectricinternals.java:90)
位于android.database.sqlite.SQLiteQuery.$$robo$init(SQLiteQuery.java)
位于android.database.sqlite.SQLiteClosable.(SQLiteClosable.java:26)
位于android.database.sqlite.SQLiteProgram.(SQLiteProgram.java:41)
位于android.database.sqlite.SQLiteQuery(SQLiteQuery.java:37)
在android.database.sqlite.SQLiteDirectCursorDriver.$$robo$$SQLiteDirectCursorDriver\u 7ac1\u查询(SQLiteDirectCursorDriver.java:44)
位于android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java)
位于android.database.sqlite.SQLiteDatabase.$$robo$$SQLiteDatabase\u ab15\u rawQueryWithFactory(SQLiteDatabase.java:1314)
位于android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java)
位于android.database.sqlite.SQLiteQueryBuilder.$$robo$$SQLiteQueryBuilder\u ba4d\u query(SQLiteQueryBuilder.java:400)
位于android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java)
位于android.database.sqlite.SQLiteQueryBuilder.$$robo$$SQLiteQueryBuilder\u ba4d\u query(SQLiteQueryBuilder.java:333)
位于android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java)
位于com.example.readingsprovider.readingContentProvider.query(readingContentProvider.java:112)
在com.example.readingsprovider.test.ContentProviderTest.TestUpdateMultiplewithout此处(ContentProviderTest.java:110)
在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处
位于sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)中
位于java.lang.reflect.Method.invoke(Method.java:597)
... 还有21个
请告诉我这是机器人的局限性,还是我的缺点?非常感谢

另外,如果反射API将失败的类名放在InstanceionException消息中,这难道不是一个梦想吗?

我一直在运行I
public Cursor rawQueryWithFactory (SQLiteDatabase.CursorFactory cursorFactory, String sql, String[] selectionArgs, String editTable, CancellationSignal cancellationSignal)
@Implementation
public Cursor rawQueryWithFactory (SQLiteDatabase.CursorFactory cursorFactory,
                                 String sql,
                                 String[] selectionArgs,
                                 String editTable,
                                 CancellationSignal cancellationSignal)
{
  return rawQueryWithFactory(cursorFactory,
                             sql,
                             selectionArgs,
                             editTable);
}