StringIndexOutOfBoundsException when loading resources (Eclipse ADT)

1,261 views
Skip to first unread message

Sean Briceland

unread,
May 31, 2014, 4:40:29 PM5/31/14
to robol...@googlegroups.com
I am new to robolectric and just set up MyTestProject as outlined at http://robolectric.org/eclipse-quick-start/. However I cannot get passed this nasty StringIndexOutOfBounds Exception in MyActivityTest setup().

All I am currently doing in setup is as creating my activity:
    

    ShadowLog.stream = System.out;

    this.activity = (MyActivity) Robolectric.buildActivity(MyActivity.class).create().get();


I have MyProject (for my android code) and MyProjectTest (for the Robolectric tests).
The StringIndexOutOfBoundsException error comes up when my Run Config Working directory is:
(other:)
${workspace_loc:myproject}

However, if I use ${workspace_loc:myprojecttest} as my working directory, it warns me about not finding the manifest.xml, but I can actually see the activity onCreate() get called (via a Log call in onCreate). But this still fails with an unknown resource error as soon as setContentView() is called. 

For full StrackTraces Both I listed them below.


Trace for StringIndexOutOfBoundsException:
ava.lang.StringIndexOutOfBoundsException: String index out of range: -9
at java.lang.String.substring(String.java:1937)
at org.robolectric.res.ResName.qualifyResName(ResName.java:51)
at org.robolectric.shadows.ShadowActivity.setThemeFromManifest(ShadowActivity.java:93)
at org.robolectric.util.ActivityController.attach(ActivityController.java:74)
at org.robolectric.util.ActivityController$1.run(ActivityController.java:112)
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 com.example.MyActivityTest.setup(MyActivityTest.java:24)
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)
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.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:250)
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:177)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
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)


And HERE is the trace for when I set working directory  ${workspace_loc:myprojecttest} :
android.content.res.Resources$NotFoundException: unknown resource 2130903041
at org.robolectric.shadows.ShadowAssetManager.getAndResolve(ShadowAssetManager.java:272)
at org.robolectric.shadows.ShadowAssetManager.getResourceValue(ShadowAssetManager.java:85)
at android.content.res.AssetManager.getResourceValue(AssetManager.java)
at android.content.res.Resources.getValue(Resources.java:1009)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2098)
at android.content.res.Resources.getLayout(Resources.java:852)
at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
at android.app.Activity.setContentView(Activity.java:1867)
at com.example.activity.MyActivity.onCreate(MyActivity.java:63)
at android.app.Activity.performCreate(Activity.java:5008)
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 com.example.MyActivityTest.setup(MyActivityTest.java:24)
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.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:250)
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:177)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
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)


Sean Briceland

unread,
Jun 2, 2014, 10:01:56 AM6/2/14
to robol...@googlegroups.com
I was able to resolve this. Problem was with setting a global custom theme and individual activity themes. 

In <application> tag I had my theme set to a custom theme which used parent as follows:
    parent="android:Theme.Holo.Light"

Then the problem was in the manifest I set an activity specific theme as:
    android:theme="@style/android:Theme.Holo.Light.NoActionBar.Fullscreen"

Luckily for me, my app does not require an actionbar for any of my activities. So I was able to update the parent of my custom theme to be "@style/android:Theme.Holo.Light.NoActionBar.Fullscreen" and removing the NoActionBar theme from all of my activities. 
Reply all
Reply to author
Forward
0 new messages