I saw many topics regarding this error, but did not find a working solution. Therefore, I will try to fully describe the problem.
I have a project and a project test. My project manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.toto.app" android:versionCode="3" android:versionName="0.3.1"> ... <application android:icon="@drawable/icon" android:label="@string/app_name"> ... </application> </manifest>
And my test project manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.toto.app.test" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="4" /> <instrumentation android:targetPackage="com.toto.app" android:name="android.test.InstrumentationTestRunner" /> <application android:icon="@drawable/icon" android:label="@string/app_name"> <uses-library android:name="android.test.runner" /> </application> </manifest>
Here is the activity I want to test: src / com / toto / app / activity / ListActivity, I have LaunchActivity (declared as a launch activity in the manifest) that trigger this action.
And in the test, my ListActivityTest is on the same path (src / com / toto / app / activity). I also tried using src / com / toto / app / test. A source:
public class ListActivityTest extends ActivityInstrumentationTestCase2<LaunchActivity>{ private Solo solo; public ListActivityTest() { super(LaunchActivity.class); } public void setUp() throws Exception { solo = new Solo(getInstrumentation(), getActivity()); solo.wait(2000); } }
LaunchActivity seems to be found, but when it starts ListActivity, I have an error:
% adb shell am instrument -w com.toto.app.test / android.test.InstrumentationTestRunner
com.toto.app.activity.ListActivityTest: INSTRUMENTATION_RESULT: shortMsg = java.lang.ClassNotFoundException INSTRUMENTATION_RESULT: longMsg = java.lang.ClassNotFoundException: com.toto.app.activity.ListActivity in the loader of the system class /android.test.runner.jar:/data/app/com.toto.app.test-2.apk:/data/app/com.toto.app-2.apk]
I donโt understand why one class is found and the other is not ... In Eclipse, it doesnโt work the same way. I tried using ListActivity directly in the test folder, but the same error. How does he create this apk to avoid some class?
This is a full stack when using adb.
Full stack in logcat eclipse:
java.lang.NoClassDefFoundError: com.toto.app.activity.ListActivity at com.toto.app.activity.LaunchActivity.onCreate(LaunchActivity.java:19) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1794) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1851) at android.app.ActivityThread.access$1500(ActivityThread.java:132) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1038) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:143) at android.app.ActivityThread.main(ActivityThread.java:4293) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:507) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.ClassNotFoundException: com.toto.app.activity.ListActivity in loader dalvik.system.PathClassLoader[/system/framework/android.test.runner.jar:/data/app/com.toto.app.test-2.apk:/data/app/com.toto.app-1.apk] at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240) at java.lang.ClassLoader.loadClass(ClassLoader.java:551) at java.lang.ClassLoader.loadClass(ClassLoader.java:511) ... 14 more