2014-09-03 10 views
8

का परीक्षण करने के लिए रोबोलेक्ट्रिक का उपयोग करते समय त्रुटि मैं अपने आवेदन से किसी गतिविधि की जांच करने के लिए रोबोलेक्ट्रिक का उपयोग कर रहा हूं। गतिविधि एक्शनबार एक्टिविटी बढ़ाती है। जब मैं गतिविधि का परीक्षण करता हूं तो मुझे त्रुटि मिलती है: "IllegalStateException: आपको इस गतिविधि के साथ थीम.एप कॉम्पैम्प थीम (या वंश) का उपयोग करने की आवश्यकता है।"एक्शनबार एक्टिविटी

मेरा परीक्षण वातावरण यह है: एंड्रॉइड स्टूडियो 0.8.6, रोबोलेक्ट्रिक 2.4-स्नैपशॉट, सपोर्ट-वी 4 लाइब्रेरी संस्करण 20.0, एपकोम्पैट-वी 7 संस्करण 20.0।

अब कक्षाओं के लिए। गतिविधि:

public class FilterActivity extends ActionBarActivity 

परीक्षण वर्ग:

@Config(emulateSdk = 18, manifest = "src/main/AndroidManifest.xml") 
@RunWith(RobolectricTestRunner.class) 
public class FilterActivityTest 
{ 
    private FilterActivity activity; 

    @Before 
    public void setUp() throws Exception 
    { 
     activity = Robolectric.buildActivity(FilterActivity.class).create().get(); 
    } 

    @After 
    public void tearDown() throws Exception 
    { 
     activity.finish(); 
    } 

    @Test 
    public void testOnCreate() 
    { 

    } 
} 

मूल्यों फ़ोल्डर से मेरे styles.xml:

<style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar"> 

</style> 

स्टैक ट्रेस: ​​

java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. 
at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:110) 
at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:57) 
at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:99) 
at ro.cursurideschimb.user.FilterActivity.onCreate(FilterActivity.java:97) 
at android.app.Activity.performCreate(Activity.java:5133) 
at org.fest.reflect.method.Invoker.invoke(Invoker.java:112) 
at org.robolectric.util.ActivityController$1.run(ActivityController.java:113) 
at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:265) 
at org.robolectric.util.ActivityController.create(ActivityController.java:110) 
at org.robolectric.util.ActivityController.create(ActivityController.java:120) 
at ro.cursurideschimb.user.FilterActivityTest.setUp(FilterActivityTest.java:38) 
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) 
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) 
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24) 
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) 
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:267) 
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) 
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) 
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) 
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) 
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) 
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) 
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) 
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) 
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:194) 
at org.junit.runners.ParentRunner.run(ParentRunner.java:309) 
at org.junit.runner.JUnitCore.run(JUnitCore.java:160) 
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134) 

के लिए धन्यवाद आपकी सहायता।

+0

क्या आपके 'एंड्रॉयड करता है: अपने AndroidManifest बिंदु में' application' तत्व की theme' संपत्ति के लिए? – iamreptar

उत्तर

0

मैं एक ही मुद्दा था, मेरा मानना ​​है कि इस @style/Theme.AppCompat.Light.DarkActionBar बनाम Theme.AppCompat.Light.DarkActionBar

<style name="Theme.MyApp" parent="Base.Theme.MyApp"> 
</style> 

<style name="Base.Theme.MyApp" parent="Theme.AppCompat.Light.DarkActionBar"> 
    <item name="colorPrimary">@color/charcoal_gray</item> 
    <item name="colorPrimaryDark">@color/black</item> 
    <item name="colorAccent">@color/white</item> 
    <item name="android:windowBackground">@color/black</item> 
</style> 

का उपयोग कर इसके अलावा, संभवतः उल्लेख के लायक के कारण होता है, कि जब समर्थन पुस्तकालय के नए संस्करण का उपयोग कर, यह स्विच करने के लिए सिफारिश की है है ActionBarActivity से AppCompatActivity क्योंकि पूर्व को अब हटा दिया गया है।

यदि आप किसी पुराने लक्ष्य SDK का उपयोग कर रहे हैं, यह आप पर लागू हो सकता है: ActionBarCompat: java.lang.IllegalStateException: You need to use a Theme.AppCompat

संबंधित मुद्दे