Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to resolve activity for: Intent

I am having a problem in running Android unit test. I got this error when I tried to run a simple test.

Here's the log:

Blockquote java.lang.RuntimeException: Unable to resolve activity for: Intent { act=android.intent.action.MAIN flg=0x10000000 cmp=com.wsandroid.Activities/.SplashActivity } at android.app.Instrumentation.startActivitySync(Instrumentation.java:371) at android.test.InstrumentationTestCase.launchActivityWithIntent(InstrumentationTestCase.java:120) at android.test.InstrumentationTestCase.launchActivity(InstrumentationTestCase.java:98) at android.test.ActivityInstrumentationTestCase2.getActivity(ActivityInstrumentationTestCase2.java:87) at com.wsandroid.test.activity.TestEULA.setUp(TestEULA.java:15) at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169) at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154) at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:430) at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1447)

This error occurs for Android less than 2.2. It works fine for Android 2.2 emulator. Yet Android 2.2 emulator has a bug of sending a key twice even though we only press it one. Application to be tested runs on Android 2.2 platform.

Appreciate if anyone of you can help me.

Dzung.

like image 372
user471915 Avatar asked Oct 11 '10 05:10

user471915


4 Answers

This can also be cause by a missing

Make sure you have a corresponding entry in your manifest.

<activity android:name=".SplashActivity"  ...
like image 62
yogurtearl Avatar answered Sep 23 '22 15:09

yogurtearl


I had a similar problem with a simple test project for an app that was just a splash screen. I found that I had implemented the constructor wrong. My initial implementation of the constructor was this...

public SplashScreenTest(){
    super("com.mycomp.myapp.SplashScreen", SplashScreen.class);
}

After some beating my head against the wall, I somehow decided to remove the SplashScreen from the pkg argument of super(). My successful implementation is now like this...

public SplashScreenTest() {
    super("com.mycomp.myapp", SplashScreen.class);
}

I hope that this helps you or others solve the problem.

like image 34
eph_tagh Avatar answered Sep 20 '22 15:09

eph_tagh


Try to check your Manifest.xml file:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.tablet.test"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">

    <uses-library android:name="android.test.runner" />
    </application>
    <uses-sdk android:minSdkVersion="8" />
    <!-- This line below! -->
    <instrumentation android:targetPackage="com.tablet.tablet"
    android:name="android.test.InstrumentationTestRunner" /> 
</manifest> 

You need to check the following line:

<instrumentation android:targetPackage="com.tablet.tablet"
android:name="android.test.InstrumentationTestRunner" /> 

So the targetPackage must be the same as in your code.

like image 7
Melroy van den Berg Avatar answered Sep 20 '22 15:09

Melroy van den Berg


I had specific similar problem while using the AndroidAnnotations lib.

Later, I found out it was due to forgetting to use the generated class (MyActivity_ instead of MyActivity).

like image 3
wkrueger Avatar answered Sep 22 '22 15:09

wkrueger