setContentView: URISyntaxException inflating TextView

115 views
Skip to first unread message

Charles Armitage

unread,
May 12, 2013, 1:00:55 PM5/12/13
to robol...@googlegroups.com
Hello, 

I'm new to Android development and Roobolectric. Following the site instructions I have created a project in Intellij. When I add a TextView to my main.xml I get the following errors:

WARNING: no system properties value for ro.build.date.utc
DEBUG: Loading resources for com.cjra.MyProject from .\res...
DEBUG: Loading resources for android from jar:C:\Users\cjra\.m2\repository\org\robolectric\android-res\4.1.2_r1_rc\android-res-4.1.2_r1_rc-real.jar!/res...
INFO: no id mapping found for android:drawable/scrollbar_handle_holo_dark; assigning ID #0x1140002
INFO: no id mapping found for android:attr/focus; assigning ID #0x1140003
INFO: no id mapping found for android:color/secondary_text_holo_dark; assigning ID #0x1140004
INFO: no id mapping found for android:color/highlighted_text_holo_dark; assigning ID #0x1140005
INFO: no id mapping found for android:color/hint_foreground_holo_dark; assigning ID #0x1140006

java.lang.RuntimeException: Failed to create a android.widget.TextView
at org.robolectric.res.builder.LayoutBuilder.constructView(LayoutBuilder.java:182)
at org.robolectric.res.builder.LayoutBuilder.create(LayoutBuilder.java:109)
at org.robolectric.res.builder.LayoutBuilder.doInflate(LayoutBuilder.java:42)
at org.robolectric.res.builder.LayoutBuilder.doInflate(LayoutBuilder.java:45)
at org.robolectric.res.builder.LayoutBuilder.inflateView(LayoutBuilder.java:62)
at org.robolectric.shadows.ShadowLayoutInflater.inflate(ShadowLayoutInflater.java:50)
at org.robolectric.shadows.ShadowLayoutInflater.inflate(ShadowLayoutInflater.java:55)
at android.view.LayoutInflater.inflate(LayoutInflater.java)
at org.robolectric.tester.android.view.RoboWindow.setContentView(RoboWindow.java:80)
at org.robolectric.shadows.ShadowActivity.setContentView(ShadowActivity.java:265)
at android.app.Activity.setContentView(Activity.java)
at com.cjra.MyProject.MyActivity.onCreate(MyActivity.java:13)
at MyActivityTest.shouldHaveHappySmiles(MyActivityTest.java:21)
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.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:280)
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:215)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:77)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at org.robolectric.res.builder.LayoutBuilder.constructView(LayoutBuilder.java:167)
at org.robolectric.res.builder.LayoutBuilder.create(LayoutBuilder.java:109)
at org.robolectric.res.builder.LayoutBuilder.doInflate(LayoutBuilder.java:42)
at org.robolectric.res.builder.LayoutBuilder.doInflate(LayoutBuilder.java:45)
at org.robolectric.res.builder.LayoutBuilder.inflateView(LayoutBuilder.java:62)
at org.robolectric.shadows.ShadowLayoutInflater.inflate(ShadowLayoutInflater.java:50)
at org.robolectric.shadows.ShadowLayoutInflater.inflate(ShadowLayoutInflater.java:55)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.robolectric.bytecode.ShadowWrangler$ShadowMethodPlan.run(ShadowWrangler.java:416)
at android.view.LayoutInflater.inflate(LayoutInflater.java)
at org.robolectric.tester.android.view.RoboWindow.setContentView(RoboWindow.java:80)
at org.robolectric.shadows.ShadowActivity.setContentView(ShadowActivity.java:265)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.robolectric.bytecode.ShadowWrangler$ShadowMethodPlan.run(ShadowWrangler.java:416)
at android.app.Activity.setContentView(Activity.java)
at com.cjra.MyProject.MyActivity.onCreate(MyActivity.java:13)
at MyActivityTest.shouldHaveHappySmiles(MyActivityTest.java:21)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
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.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:280)
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:215)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:77)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
... 1 more
Caused by: android.content.res.Resources$NotFoundException: File jar:C:\Users\cjra\.m2\repository\org\robolectric\android-res\4.1.2_r1_rc\android-res-4.1.2_r1_rc-real.jar!/res/color/secondary_text_holo_dark.xml from color state list resource ID #0x1140004
at android.content.res.Resources.loadColorStateList(Resources.java:2048)
at android.content.res.TypedArray.getColorStateList(TypedArray.java:342)
at android.widget.TextView.__constructor__(TextView.java:503)
at android.widget.TextView.<init>(TextView.java:447)
at android.widget.TextView.<init>(TextView.java:442)
at org.robolectric.res.builder.LayoutBuilder.constructView(LayoutBuilder.java:167)
at org.robolectric.res.builder.LayoutBuilder.create(LayoutBuilder.java:109)
at org.robolectric.res.builder.LayoutBuilder.doInflate(LayoutBuilder.java:42)
at org.robolectric.res.builder.LayoutBuilder.doInflate(LayoutBuilder.java:45)
at org.robolectric.res.builder.LayoutBuilder.inflateView(LayoutBuilder.java:62)
at org.robolectric.shadows.ShadowLayoutInflater.inflate(ShadowLayoutInflater.java:50)
at org.robolectric.shadows.ShadowLayoutInflater.inflate(ShadowLayoutInflater.java:55)
at android.view.LayoutInflater.inflate(LayoutInflater.java)
at org.robolectric.tester.android.view.RoboWindow.setContentView(RoboWindow.java:80)
at org.robolectric.shadows.ShadowActivity.setContentView(ShadowActivity.java:265)
at android.app.Activity.setContentView(Activity.java)
at com.cjra.MyProject.MyActivity.onCreate(MyActivity.java:13)
at MyActivityTest.shouldHaveHappySmiles(MyActivityTest.java:21)
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.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:280)
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:215)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:77)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
... 1 more
Caused by: java.lang.IllegalArgumentException: Illegal character in opaque part at index 6: jar:C:\Users\cjra\.m2\repository\org\robolectric\android-res\4.1.2_r1_rc\android-res-4.1.2_r1_rc-real.jar!/res/color/secondary_text_holo_dark.xml
at java.net.URI.create(URI.java:859)
at org.robolectric.res.Fs.fileFromPath(Fs.java:29)
at org.robolectric.shadows.ShadowResources.loadXmlResourceParser(ShadowResources.java:353)
at android.content.res.Resources.loadXmlResourceParser(Resources.java)
at android.content.res.Resources.loadColorStateList(Resources.java:2043)
... 37 more
Caused by: java.net.URISyntaxException: Illegal character in opaque part at index 6: jar:C:\Users\cjra\.m2\repository\org\robolectric\android-res\4.1.2_r1_rc\android-res-4.1.2_r1_rc-real.jar!/res/color/secondary_text_holo_dark.xml
at java.net.URI$Parser.fail(URI.java:2829)
at java.net.URI$Parser.checkChars(URI.java:3002)
at java.net.URI$Parser.parse(URI.java:3039)
at java.net.URI.<init>(URI.java:595)
at java.net.URI.create(URI.java:857)
at org.robolectric.res.Fs.fileFromPath(Fs.java:29)
at org.robolectric.shadows.ShadowResources.loadXmlResourceParser(ShadowResources.java:353)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.robolectric.bytecode.ShadowWrangler$ShadowMethodPlan.run(ShadowWrangler.java:416)
at android.content.res.Resources.loadXmlResourceParser(Resources.java)
at android.content.res.Resources.$$robo$$Resources_fb43_loadColorStateList(Resources.java:2043)
at android.content.res.Resources.loadColorStateList(Resources.java)
at android.content.res.TypedArray.$$robo$$TypedArray_42b1_getColorStateList(TypedArray.java:342)
at android.content.res.TypedArray.getColorStateList(TypedArray.java)
at android.widget.TextView.$$robo$$TextView_347d___constructor__(TextView.java:503)
at android.widget.TextView.<init>(TextView.java:447)
at android.widget.TextView.<init>(TextView.java:442)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at org.robolectric.res.builder.LayoutBuilder.constructView(LayoutBuilder.java:167)
at org.robolectric.res.builder.LayoutBuilder.create(LayoutBuilder.java:109)
at org.robolectric.res.builder.LayoutBuilder.doInflate(LayoutBuilder.java:42)
at org.robolectric.res.builder.LayoutBuilder.doInflate(LayoutBuilder.java:45)
at org.robolectric.res.builder.LayoutBuilder.inflateView(LayoutBuilder.java:62)
at org.robolectric.shadows.ShadowLayoutInflater.inflate(ShadowLayoutInflater.java:50)
at org.robolectric.shadows.ShadowLayoutInflater.inflate(ShadowLayoutInflater.java:55)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.robolectric.bytecode.ShadowWrangler$ShadowMethodPlan.run(ShadowWrangler.java:416)
at android.view.LayoutInflater.inflate(LayoutInflater.java)
at org.robolectric.tester.android.view.RoboWindow.setContentView(RoboWindow.java:80)
at org.robolectric.shadows.ShadowActivity.setContentView(ShadowActivity.java:265)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.robolectric.bytecode.ShadowWrangler$ShadowMethodPlan.run(ShadowWrangler.java:416)
at android.app.Activity.setContentView(Activity.java)
at com.cjra.MyProject.MyActivity.onCreate(MyActivity.java:13)
at MyActivityTest.shouldHaveHappySmiles(MyActivityTest.java:21)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
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.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:280)
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:215)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
... 1 more


Process finished with exit code -1

main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
    >
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Text"
        android:id="@+id/textView"
        android:layout_gravity="right|center_vertical"/>
</LinearLayout>

MyActivity.java:

package com.cjra.MyProject;

import android.app.Activity;
import android.os.Bundle;

public class MyActivity extends Activity {
    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

MyActivityTest.java:

import android.widget.TextView;
import com.cjra.MyProject.MyActivity;
import com.cjra.MyProject.R;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertEquals;

@RunWith(RobolectricTestRunner.class)
public class MyActivityTest {

    @Test
    public void shouldHaveHappySmiles() {
        MyActivity act = new MyActivity();

        String appName = act.getResources().getString(R.string.app_name);
        assertEquals(appName, "MyProject");

        act.onCreate(null);
        TextView text = (TextView)act.findViewById(R.id.textView);
        assertNotNull(text);
    }
}

Searching I cannot find anone with similar problems. Any thoughts?

I'm using:
robolectric-2.0-rc1-jar-with-dependencies.jar
Android SDK 4.2.2
running on Windows

Thanks.

Charles Armitage

unread,
May 12, 2013, 4:42:54 PM5/12/13
to robol...@googlegroups.com
Hi,

Answering my own post. I've found that running the tests in a Linux VM works fine so there does seem to be a Windows related problem with Robolectric 2.0.

Charles
Reply all
Reply to author
Forward
0 new messages