Note that there are some explanatory texts on larger screens.

plurals
  1. PORuntime Exception in Android JUnit testing
    text
    copied!<p>I have a simple HelloWorld Activity that I try to test with an Android JUnit test. The application itself runs like it should but the test fails with an </p> <p>"java.lang.RuntimeException: Unable to resolve activity for: Intent { action=android.intent.action.MAIN flags=0x10000000 comp={no.helloworld.HelloWorld/no.helloworld.HelloWorld} } at no.helloworld.test.HelloWorldTestcase.setUp(HelloWorldTestcase.java:21)"</p> <p>This is my activity class:</p> <blockquote> <p>package no.helloworld;</p> <p>import android.app.Activity; import</p> <p>android.os.Bundle;</p> <p>public class HelloWorld extends Activity {</p> <p>@Override</p> <pre><code>public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } } </code></pre> </blockquote> <p>And the test:</p> <blockquote> <p>public class HelloWorldTestcase extends ActivityInstrumentationTestCase2 {</p> <pre><code>private HelloWorld myActivity; private TextView mView; private String resourceString; </code></pre> </blockquote> <pre><code>public HelloWorldTestcase() { super("no.helloworld.HelloWorld", HelloWorld.class); } @Override protected void setUp() throws Exception { super.setUp(); myActivity = this.getActivity(); mView = (TextView) myActivity.findViewById(no.helloworld.R.id.txt1); resourceString = myActivity .getString(no.helloworld.R.string.helloworld); } public void testPreconditions() { assertNotNull(mView); } public void testText() { assertEquals(resourceString, (String) mView.getText()); } protected void tearDown() throws Exception { super.tearDown(); } </code></pre> <p>Why does the test fail? The activity is (of course) defined in AndroidManifest.xml and the application runs as it should.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload