2016-09-27 12 views
1

私は奇妙なIllegalStateExceptionに遭遇しています。私はRobolectricに問題があると思います。これは、スタックトレースである:Robolectric IllegalState例外

java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. 

at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:340) 
at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:309) 
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:273) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:136) 
at com.sr.dd.dd_app.screens.main.MainActivity.onCreate(MainActivity.java:87) 

MainActivity.javaライン87

setContentView(R.layout.activity_main); 

activity_main.xml:

:活動がインスタンス化される

<?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/main_drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent"> <!-- The main content view --> <FrameLayout android:id="@+id/main_content_frame" android:layout_width="match_parent" android:layout_height="match_parent" /> <!-- The navigation drawer --> <ListView android:id="@+id/main_left_drawer" android:layout_width="280dp" android:layout_height="match_parent" android:layout_gravity="left|start" android:background="#FFFFFF" /> </android.support.v4.widget.DrawerLayout>

単体テスト

@RunWith(RobolectricTestRunner.class) 
@Config(constants = BuildConfig.class, shadows = {ShadowGoogleApiAvailability.class}, manifest="app/src/main/AndroidManifest.xml") 
public class ScreenUnitTest { 
    ... //Some unimportant stuff 
    @Before 
    public void setUp() { 
     ... //More unimportant stuff 
     mainActivity = Robolectric.setupActivity(MainActivity.class); 
    } 
} 

build.gradle:誰がこれを見ている場合だけで不思議23

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    androidTestCompile 'junit:junit:4.12' 
    androidTestCompile 'org.mockito:mockito-core:1.+' 
    androidTestCompile 'com.google.dexmaker:dexmaker:1.2' 
    androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2' 
    androidTestCompile 'com.android.support:support-annotations:23.3.0' 
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1' 
    testCompile 'junit:junit:4.12' 
    testCompile 'org.mockito:mockito-core:1.+' 
    testCompile 'org.robolectric:robolectric:3.1' 
    testCompile "org.robolectric:shadows-support-v4:3.1" 
    testCompile "org.robolectric:shadows-play-services:3.1" 
    testCompile 'org.robolectric:shadows-maps:3.1' 
    testCompile 'org.khronos:opengl-api:gl1.1-android-2.1_r1' 
    testCompile 'com.android.support:design:23.3.0' 

    compile 'com.android.support:design:23.3.0' 
    compile 'com.android.support:support-annotations:23.3.0' 
    compile 'com.android.support:appcompat-v7:23.3.0' 
    compile 'com.android.support:support-v4:23.3.0' 
    compile 'com.google.android.gms:play-services:8.1.0' 
    compile 'com.android.support:design:23.0.+' 
    compile 'com.android.support:cardview-v7:23.0.+' 
    compile 'com.android.support:recyclerview-v7:23.0.+' 
    compile 'joda-time:joda-time:2.9.4' 
} 

は、SDKのバージョンでコンパイルします。それは他の質問とよく似ていますが、私が見つけた答えは役に立たない。

+0

AppCompatActivityの代わりにActivityを使用してください。 –

+0

@ MarkShen私はDrawerLayoutを使用しようとしています。これは、サポート-v4でのみ使用しています。 –

+0

@マーク私はすべてのフラグメントを非サポートフラグメントに変更し、アクティビティを非サポートアクティビティに変更しました。私は今、IllegalStateException:executePendingTransactionsへの再帰的なエントリを取得します。 :/ –

答えて

1

設定タグからマニフェストエントリを削除すると、robolectricはそれを見つけます。または、必要に応じて、ビルドディレクトリにあるマニフェストファイルを使用します。これはよくある間違いであり、robolectricは何かを見つけることができません。

+0

それは何もしなかった。私はすべての私のフラグメントを非サポートフラグメントに変更し、私はアクティビティを非サポートアクティビティに変更しました。私は今、IllegalStateException:executePendingTransactionsへの再帰的なエントリを取得します。 –

+0

サポートライブラリは、互換性だけでなく、SDK –

+0

で利用できない新しいAPIにも存在します。再帰呼び出しの問題については、コードを確認する必要があります。このようなエラーは、フラグメントロジックの追加と置換が一般的です。 – nenick