RuntimeException: Unable to resolve activity for: Intent

4,126 views
Skip to first unread message

andrijaperovic

unread,
Jun 24, 2010, 7:53:29 PM6/24/10
to Robotium Developers
Hi everyone,

the below attached code is working fine on an emulator running 2.1-
update1, however when I try running it on a physical phone (my android
junit class), the failure trace
complains with the following error. Any help would be appreciated.

java.lang.RuntimeException: Unable to resolve activity for: Intent
{ act=android.intent.action.MAIN flg=0x10000000
cmp=com.asurion.android.mobilerecovery.activity.MainActivity/
com.asurion.android.mobilerecovery.activity.MainActivity }
at android.app.Instrumentation.startActivitySync(Instrumentation.java:
447)
at
android.test.InstrumentationTestCase.launchActivityWithIntent(InstrumentationTestCase.java:
106)
at
android.test.ActivityInstrumentationTestCase2.getActivity(ActivityInstrumentationTestCase2.java:
89)
at
com.asurion.android.mobilerecovery.tests.MainActivityTest.setUp(MainActivityTest.java:
45)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:164)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:151)
at
android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:
425)
at android.app.Instrumentation
$InstrumentationThread.run(Instrumentation.java:1520)

Any ideas?

/*
*
* Simple test case for automating a new user registration / login to
Breezie.
* TODO expand to test all e-mail/pin combinations.
* @author Andrija Perovic
*
*/


public class MainActivityTest extends
ActivityInstrumentationTestCase2<MainActivity> {

private Solo solo;
public static final int N = 50;
private Intent mStartIntent;

public MainActivityTest() {
super("com.asurion.android.mobilerecovery.activity.MainActivity",
MainActivity.class);

}

public void setUp()
{
mStartIntent = new Intent(Intent.ACTION_MAIN);
setActivityIntent(mStartIntent);
solo = new Solo(getInstrumentation(), getActivity());
}



@Smoke
public void testMain(){

while(solo.searchButton("Begin Setup")== false){
//wait until connection to server starts up
}
solo.clickOnButton("Begin Setup");
solo.assertCurrentActivity("Expected ApplicationFlow activity",
"ApplicationFlowActivity"); //Assert that MainActivity activity is
opened
solo.setActivityOrientation(Solo.LANDSCAPE);
solo.clickOnButton("Yes");
solo.assertCurrentActivity("Expected ChoosePin activity",
"ChoosePinActivity"); //Assert that MainActivity activity is opened
//TODO automate this against all possible username/password
combinations
String regex =
"[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789]
{1,10}";
String regex2 =
"[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789]
{1,10}";
Xeger generator = new Xeger(regex);
Xeger generator1 = new Xeger(regex2);
final String TAG = generator.generate() + "@" +
generator1.generate() + ".com";
solo.enterText(0, TAG);//enter username
solo.enterText(1, "5321");//enter pin
solo.setActivityOrientation(Solo.PORTRAIT);//change screen
orientation
solo.sendKey(Solo.DOWN);
solo.clickOnButton("OK"); // step through choosepin screen
while(solo.searchButton("OK")== false){
//wait until choosepin activity completes
}
solo.clickOnButton("OK");//confirm recovery account is valid
/*
while(solo.searchButton("Yes")== false){
//wait until recovery account view finishes
}
*/
solo.sleep(2000);
solo.clickOnButton("Yes"); //save contacts from server to phone
while(solo.searchButton("OK")== false){
//sleep while waiting for contacts to be saved to phone
}
solo.clickOnButton("OK");

Log.d("TESTMSG", "Test passed with " + TAG);
//reset to default state
this.reset();


}



private void reset(){
solo.sleep(4000);//wait for preceding activity to complete

//enters secret menu and resets application to default
for(int i=1; i < 7;i++){
if((i%2)==1){
for(int k=0; k<i; k++ ){
solo.instr.sendKeyDownUpSync(KeyEvent.KEYCODE_VOLUME_UP);
}
}
else{
for(int k=0; k<i; k++){
solo.instr.sendKeyDownUpSync(KeyEvent.KEYCODE_VOLUME_DOWN);
}
}
}

solo.searchButton("Reset");
while(solo.searchButton("Reset")== false){
//wait until secret menu displayed
}
solo.clickOnButton("Reset");
while(solo.searchButton("Yes")== false){
//wait until confirmation box
}
solo.clickOnButton("Yes");
solo.goBack();solo.goBack();
}

@Override
public void tearDown() throws Exception{
try {
solo.finalize();
} catch (Throwable e) {
e.printStackTrace();
}
getActivity().finish();
super.tearDown();
}
}


Thanks,
Andy P.




Hugo Josefson (Jayway)

unread,
Jun 25, 2010, 3:41:30 AM6/25/10
to Robotium Developers
Hi Andy!

The first problem I see is in your constructor:

> public MainActivityTest() {
> super("com.asurion.android.mobilerecovery.activity.MainActivity", MainActivity.class);
> }

The string is supposed to be only the package name of the application
you wish to test. That's the <manifest package="..." > parameter from
the very top of the application project's AndroidManifest.xml, and the
same as the <instrumentation android:targetPackage="..." > parameter
in your test project's AndroidManifest.xml.

Thanks,
Hugo

andrijaperovic

unread,
Jun 25, 2010, 5:05:48 PM6/25/10
to Robotium Developers
That worked great! Cant believe i missed such an obvious bug. Thanks,
Hugo.

Cheers,
Andy P.

On Jun 25, 2:41 am, "Hugo Josefson (Jayway)" <h...@josefson.org>
wrote:

Rich

unread,
Aug 23, 2010, 9:55:04 PM8/23/10
to Robotium Developers
I've had a similar problem. Before I understood that the first param
to the ctor::super() should match the package name specified in the
target application's manifest, I was able to work around the problem
by specifying Android 2.2 as the target runtime. Since then I've
modified my test case to correct the package name in the test file and
now I can run the test on a 2.1 runtime. Very interesting...

On Jun 25, 1:41 am, "Hugo Josefson (Jayway)" <h...@josefson.org>
wrote:
> Hi Andy!
>
> The first problem I see is in your constructor:
>
> > public MainActivityTest() {
> >   super("com.asurion.android.mobilerecovery.activity.MainActivity", MainActivity.class);
> > }
>
> The string is supposed to be only the package name of the application
> you wish to test. That's the <manifest package="..." > parameter from
> the very top of the application project's AndroidManifest.xml, and the
> same as the <instrumentation android:targetPackage="..." > parameter
> in your test project's AndroidManifest.xml.
>
> Thanks,
> Hugo
>
> On Jun 25, 1:53 am, andrijaperovic <andrijapero...@gmail.com> wrote:
>
>
>
>
>
>
>
> > Hi everyone,
>
> > the below attached code is working fine on an emulator running 2.1-
> > update1, however when I try running it on a physical phone (my android
> > junit class), the failure trace
> > complains with the following error. Any help would be appreciated.
>
> > java.lang.RuntimeException: Unable to resolve activity for: Intent
> > { act=android.intent.action.MAIN flg=0x10000000
> > cmp=com.asurion.android.mobilerecovery.activity.MainActivity/
> > com.asurion.android.mobilerecovery.activity.MainActivity }
> > at android.app.Instrumentation.startActivitySync(Instrumentation.java:
> > 447)
> > at
> > android.test.InstrumentationTestCase.launchActivityWithIntent(Instrumentati onTestCase.java:
> > 106)
> > at
> > android.test.ActivityInstrumentationTestCase2.getActivity(ActivityInstrumen tationTestCase2.java:
> > 89)
> > at
> > com.asurion.android.mobilerecovery.tests.MainActivityTest.setUp(MainActivit yTest.java:
Reply all
Reply to author
Forward
0 new messages