Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No issue ( java.lang.StringIndexOutOfBoundsException: String index out of range: -9) #20

Open
misrakli opened this issue May 1, 2015 · 5 comments

Comments

@misrakli
Copy link

misrakli commented May 1, 2015

I added a very simple activity with a very simple layout and i get following exception when running the test.

java.lang.StringIndexOutOfBoundsException: String index out of range: -9
at java.lang.String.substring(String.java:1954)
at org.robolectric.res.ResName.qualifyResName(ResName.java:51)
at org.robolectric.shadows.ShadowAssetManager$StyleResolver.getParent(ShadowAssetManager.java:466)
at org.robolectric.shadows.ShadowAssetManager$StyleResolver.getAttrValue(ShadowAssetManager.java:415)
at org.robolectric.shadows.ShadowResources.getOverlayedThemeValue(ShadowResources.java:295)
at org.robolectric.shadows.ShadowResources.attrsToTypedArray(ShadowResources.java:134)
at org.robolectric.shadows.ShadowResources.access$000(ShadowResources.java:51)
at org.robolectric.shadows.ShadowResources$ShadowTheme.obtainStyledAttributes(ShadowResources.java:489)
at android.content.res.Resources$Theme.obtainStyledAttributes(Resources.java)
at android.content.Context.obtainStyledAttributes(Context.java:472)
at android.view.View.__constructor__(View.java:3677)
at android.view.View.<init>(View.java)

The layout is very simple (empty).

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:orientation="vertical"
          android:layout_width="match_parent"
          android:layout_height="match_parent">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/myId"/>
</LinearLayout>

The Test is only creating the activity.

@RunWith(CustomTestRunner.class)
@Config(constants = BuildConfig.class)
public class TestSimpleActivity
{
 @Test
public void test()
{
    SimpleActivity activity =  Robolectric.buildActivity(SimpleActivity.class).create().start().resume().visible().get();

    Assert.assertEquals(true, "test".equals("fail"));
}
}

Any ideas or suggestions?

@nenick
Copy link
Owner

nenick commented May 1, 2015

Looks like there are issues with the styling. Did you add the shadow-v4 dependencies?

@misrakli
Copy link
Author

misrakli commented May 3, 2015

Indeed the problem is the missing styling. I have a multimodule project setup, where all my business logic (activities, fragments) and presentation layer components (style, resources) are in a android library ('core' in your example), and a very thin app module for configuration of the core library.
In the app module i didn't have a styles.xml, in the app modules AndroidManifest.xml I set the style to a style defined in the core library.
When i am now adding an Activity and a layout to the app module without defining a style in the app module, the tests don't run. This causes the StringIndexOutOfBoundsException.

When I am adding a styles.xml in the app module and set the parent of the style to style defined in the core library the tests are not running. There is an "endless loop" (waited 5 minutes) while trying to run the task testDebug, it doesnt finish.
Edit: After 7 min i got following exception: java.lang.OutOfMemoryError: Java heap space

After adding a styles.xml to the app module and changing the style in the apps AndrodiManifest.xml to the app modules style the test works.
But this is not the way i want to solve the problem, because the app should use the style defined in the core library module. Is this possible?

@nenick
Copy link
Owner

nenick commented May 3, 2015

I can't reproduce it. I deleted the style.xml from the app module and did a ./gradlew clean app:test and the tests run like expected. Best would be if your fork this project and show me how you have setup your styles to get this issue.

@misrakli
Copy link
Author

misrakli commented May 4, 2015

I forked the project but cannot reproduce it for now, too. Maybe I have to add more and more "features" from my real project.The main difference i think is using the v4-support library.

@nenick
Copy link
Owner

nenick commented May 4, 2015

Perhaps same issue like robolectric/robolectric#1736 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants