java.lang.NoClassDefFoundError: android/test/ActivityInstrumentationTestCase2 - android

I have created test project...I have updloaded junit.jar in the (Run time configuration class path --> user entries --> junit.jar
I am getting below errror when i run the code...
java.lang.NoClassDefFoundError: android/test/ActivityInstrumentationTestCase2
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunner.java:693)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClasses(RemoteTestRunner.java:429)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.ClassNotFoundException: android.test.ActivityInstrumentationTestCase2
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
... 17 more

You need to run it as Android JUnit test, instead of JUnit test.
Go to the project in the project explorer->right click->Android JUnit test

android.test.ActivityInstrumentationTestCase2 is not in the JUnit JAR that you claim to have added to classpath.
That looks like one of yours.
Did you compile the code? If not, please do so.
Did you add the path to the location where your .class files are written? If not, please do so.

Follow these instructions: http://developer.android.com/guide/developing/testing/testing_eclipse.html
Basically, you don't have to add junit.jar to your classpath.

I had the similar problem. For me Changing the "Order and Export" (properties->build Path->Order and Export) of robotium-solo.jar i.e moving it to the top and explicitly selecting run as 'android JUnit test' by right clicking the project solved the problem. Also try running the sample project provided.

It might sound strange. but all you need to do is import solo before you import the class and it works. At least it did for me. i dont know why i tried that but all it needed was to cut the import com.jayway.android.robotium.solo.Solo; and paste it just after the package.

Related

(Internal Error) Opening Android Studio in School Computer

I have declared both system and user environment variables and setup everything I thought was needed. Getting this screen when attempting to open:
I have reinstalled Android Studio with admin privileges. Still nothing.
Does anyone know what the problem is? Let me know if information is insufficient.
edit 1: copyable error message
Internal Error. Please report to https://code.google.com/p/android/issues
com.intellij.ide.plugins.PluginManager$StartupAbortedException: Fatal error initializing 'com.intellij.debugger.DebuggerManager'
at com.intellij.ide.plugins.PluginManager.handleComponentError(PluginManager.java:256)
at com.intellij.openapi.components.impl.PlatformComponentManagerImpl.handleInitComponentError(PlatformComponentManagerImpl.java:43)
at com.intellij.openapi.components.impl.ComponentManagerImpl$ComponentConfigComponentAdapter.getComponentInstance(ComponentManagerImpl.java:540)
at com.intellij.openapi.components.impl.ComponentManagerImpl.createComponents(ComponentManagerImpl.java:123)
at com.intellij.openapi.components.impl.ComponentManagerImpl.init(ComponentManagerImpl.java:107)
at com.intellij.openapi.components.impl.ComponentManagerImpl.init(ComponentManagerImpl.java:90)
at com.intellij.openapi.project.impl.ProjectImpl.init(ProjectImpl.java:282)
at com.intellij.openapi.project.impl.ProjectManagerImpl.initProject(ProjectManagerImpl.java:231)
at com.intellij.openapi.project.impl.ProjectManagerImpl.access$300(ProjectManagerImpl.java:68)
at com.intellij.openapi.project.impl.ProjectManagerImpl$3.run(ProjectManagerImpl.java:311)
at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:446)
at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:392)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:54)
at com.intellij.openapi.progress.impl.CoreProgressManager.executeNonCancelableSection(CoreProgressManager.java:170)
at com.intellij.openapi.project.impl.ProjectManagerImpl.getDefaultProject(ProjectManagerImpl.java:306)
at com.android.tools.idea.sdk.IdeSdks.getAndroidSdkPath(IdeSdks.java:90)
at com.android.tools.idea.startup.GradleSpecificInitializer.setupSdks(GradleSpecificInitializer.java:282)
at com.android.tools.idea.startup.GradleSpecificInitializer.run(GradleSpecificInitializer.java:114)
at com.android.tools.idea.AndroidInitialConfigurator.activateAndroidStudioInitializerExtensions(AndroidInitialConfigurator.java:198)
at com.android.tools.idea.AndroidInitialConfigurator.<init>(AndroidInitialConfigurator.java:65)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.picocontainer.defaults.InstantiatingComponentAdapter.newInstance(InstantiatingComponentAdapter.java:193)
at org.picocontainer.defaults.ConstructorInjectionComponentAdapter$1.run(ConstructorInjectionComponentAdapter.java:220)
at org.picocontainer.defaults.ThreadLocalCyclicDependencyGuard.observe(ThreadLocalCyclicDependencyGuard.java:53)
at org.picocontainer.defaults.ConstructorInjectionComponentAdapter.getComponentInstance(ConstructorInjectionComponentAdapter.java:248)
at com.intellij.util.pico.ConstructorInjectionComponentAdapter.getComponentInstance(ConstructorInjectionComponentAdapter.java:59)
at com.intellij.openapi.components.impl.ComponentManagerImpl$ComponentConfigComponentAdapter.getComponentInstance(ComponentManagerImpl.java:499)
at com.intellij.openapi.components.impl.ComponentManagerImpl.createComponents(ComponentManagerImpl.java:123)
at com.intellij.openapi.application.impl.ApplicationImpl.access$801(ApplicationImpl.java:92)
at com.intellij.openapi.application.impl.ApplicationImpl$12.run(ApplicationImpl.java:500)
at com.intellij.openapi.progress.impl.CoreProgressManager$2.run(CoreProgressManager.java:142)
at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:446)
at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:392)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:54)
at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:127)
at com.intellij.openapi.application.impl.ApplicationImpl.createComponents(ApplicationImpl.java:516)
at com.intellij.openapi.components.impl.ComponentManagerImpl.init(ComponentManagerImpl.java:107)
at com.intellij.openapi.application.impl.ApplicationImpl.load(ApplicationImpl.java:458)
at com.intellij.openapi.application.impl.ApplicationImpl.load(ApplicationImpl.java:450)
at com.intellij.idea.IdeaApplication.run(IdeaApplication.java:197)
at com.intellij.idea.MainImpl$1$1$1.run(MainImpl.java:52)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:366)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: com/sun/jdi/Value
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.sun.proxy.$Proxy47.<clinit>(Unknown Source)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.reflect.Proxy.newProxyInstance(Unknown Source)
at com.intellij.util.EventDispatcher.<init>(EventDispatcher.java:75)
at com.intellij.util.EventDispatcher.create(EventDispatcher.java:42)
at com.intellij.debugger.impl.DebuggerStateManager.<init>(DebuggerStateManager.java:29)
at com.intellij.debugger.impl.DebuggerManagerImpl$MyDebuggerStateManager.<init>(DebuggerManagerImpl.java:606)
at com.intellij.debugger.impl.DebuggerManagerImpl$MyDebuggerStateManager.<init>(DebuggerManagerImpl.java:606)
at com.intellij.debugger.impl.DebuggerManagerImpl.<init>(DebuggerManagerImpl.java:81)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.picocontainer.defaults.InstantiatingComponentAdapter.newInstance(InstantiatingComponentAdapter.java:193)
at org.picocontainer.defaults.ConstructorInjectionComponentAdapter$1.run(ConstructorInjectionComponentAdapter.java:220)
at org.picocontainer.defaults.ThreadLocalCyclicDependencyGuard.observe(ThreadLocalCyclicDependencyGuard.java:53)
at org.picocontainer.defaults.ConstructorInjectionComponentAdapter.getComponentInstance(ConstructorInjectionComponentAdapter.java:248)
at com.intellij.util.pico.ConstructorInjectionComponentAdapter.getComponentInstance(ConstructorInjectionComponentAdapter.java:59)
at com.intellij.openapi.components.impl.ComponentManagerImpl$ComponentConfigComponentAdapter.getComponentInstance(ComponentManagerImpl.java:499)
... 56 more
Caused by: java.lang.ClassNotFoundException: com.sun.jdi.Value
at com.intellij.util.lang.UrlClassLoader.findClass(UrlClassLoader.java:207)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 80 more
edit 2: my JAVA_HOME user variable
Does it have to be like this in system variables as well?
In order to fix this issue, please ensure your JAVA_HOME is pointing to C:\Program Files\Java\jdk1.8.0_102 (Java SE Development Kit) instead of C:\Program Files\Java\jre1.8.0_102 (Java SE Runtime Environment).
In fact, JRE is located inside JDK folder.
If you haven't installed JDK yet, please do it following next link: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html?ssSourceSiteId=otnes
Got from:
https://code.google.com/p/android/issues/detail?id=211766
It's a JDK issue with Android Studio.
Try to set JAVA_HOME to JDK folder
And to set %JAVA_HOME%\bin to the Path environment variable with the JAVA_HOME environment variable pointing to the jdk folder.
Remember note: You might need to restart Windows after changing the environment variable
Sources :
code.google.com/p/android/issues/detail?id=211766
Android Studio Won't Start (com.sun.jdi.Value Not Found)
How to set java_home on Windows 7?
Try turning on HAXM at the boot time of your pc and checking all the required plugins of Android studio.
Thanks..

Impossible to mock one class with mockito: Receive NoClassDefFoundError

I have around 100 unit test in my Android project. Everything work perfectly. I use JUnit + Mockito + PowerMock (when dealing with difficult static class).
While writing my latest test, I was surprise with this very strange error that I don't understand.
When I do this in the setUp() function:
playerAccessor = mock(PlayerAccessor.class);
All the tests crash with this very strange error:
java.lang.NoClassDefFoundError: android/media/MediaPlayer$OnCompletionListener
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.powermock.core.classloader.MockClassLoader.loadModifiedClass(MockClassLoader.java:178)
at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass(DeferSupportingClassLoader.java:68)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.getDeclaredMethods(Unknown Source)
at org.mockito.cglib.core.ReflectUtils.addAllMethods(ReflectUtils.java:349)
at org.mockito.cglib.proxy.Enhancer.getMethods(Enhancer.java:422)
at org.mockito.cglib.proxy.Enhancer.generateClass(Enhancer.java:457)
at org.mockito.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
at org.mockito.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:217)
at org.mockito.cglib.proxy.Enhancer.createHelper(Enhancer.java:378)
at org.mockito.cglib.proxy.Enhancer.createClass(Enhancer.java:318)
at org.mockito.internal.creation.jmock.ClassImposterizer.createProxyClass(ClassImposterizer.java:124)
at org.mockito.internal.creation.jmock.ClassImposterizer.imposterise(ClassImposterizer.java:60)
at org.mockito.internal.creation.jmock.ClassImposterizer.imposterise(ClassImposterizer.java:52)
at org.mockito.internal.creation.CglibMockMaker.createMock(CglibMockMaker.java:24)
at org.powermock.api.mockito.internal.mockmaker.PowerMockMaker.createMock(PowerMockMaker.java:43)
at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:32)
at org.mockito.internal.MockitoCore.mock(MockitoCore.java:59)
at org.mockito.Mockito.mock(Mockito.java:1258)
at org.mockito.Mockito.mock(Mockito.java:1135)
at com.stingray360.clap.ondemand.OnDemandMessageHandlerTest.setUp(OnDemandMessageHandlerTest.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.internal.runners.MethodRoadie.runBefores(MethodRoadie.java:133)
at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:96)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.executeTest(PowerMockJUnit44RunnerDelegateImpl.java:294)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.executeTestInSuper(PowerMockJUnit47RunnerDelegateImpl.java:127)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.executeTest(PowerMockJUnit47RunnerDelegateImpl.java:82)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runBeforesThenTestThenAfters(PowerMockJUnit44RunnerDelegateImpl.java:282)
at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:87)
at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:50)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.invokeTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:207)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.runMethods(PowerMockJUnit44RunnerDelegateImpl.java:146)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$1.run(PowerMockJUnit44RunnerDelegateImpl.java:120)
at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.run(PowerMockJUnit44RunnerDelegateImpl.java:122)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:106)
at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:53)
at org.powermock.modules.junit4.PowerMockRunner.run(PowerMockRunner.java:59)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.ClassNotFoundException: android.media.MediaPlayer$OnCompletionListener
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 62 more
My only clue is that the PlayerAccessor have a function called register which take an object Player which implement the OnCompletionListener interface. But I'm not mocking the Player, I'm mocking the PlayerAccessor.
Do I need to specify something in my mock function so it doesn't try to mock every object used by the PlayerAccessor? Is it something missing from my test (import???).
EDIT
One answer suggest me to put the needed library (com.google.android) in the "test" scope but since it's the android library, the scope NEED to be "provided". If I change it, it's true that my unit test start to work but when I run the app, I receive big errors in the console telling me that it's a very bad thing to do to include the android jar... So what are the other solution???
If the class you're mocking imports another class you have to have that class on the classpath or the class loader will fail, regardless whether you're actually using any of the functionality afforded by it.
If you're using maven for builds you can easily add a dependency jar with test scope
Eclipse should respect pom configuration

android-cts-4.4-r3 gives NoClassDefFoundError while running cts-tradefed

I am trying to run Android CTS tests on Windows using Cygwin for android-cts-4.4_r3-linux_x86-arm.
When I run ./cts-tradefed I get following error:
java.lang.NoClassDefFoundError: com/android/cts/tradefed/command/CtsConsole
Caused by: java.lang.ClassNotFoundException: com.android.cts.tradefed.command.CtsConsole
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: com.android.cts.tradefed.command.CtsConsole. Program will exit.
Exception in thread "main"
Do I need to modify cts-tradefed?
The cts-tradefed file in only for linux I guess. For windows you have to create new batch file. e.g. cts_run.bat and put below code in file. Make sure you give path according to your system. Below code worked for Lollipop.
set SDK_ROOT=C:\Program Files\Java\jdk1.7.0_67
java -Xmx512M -cp C:\Users\Desktop\android-cts-5.0_r2-linux_x86-arm\android-cts\tools\cts-tradefed.jar;C:\Users\Desktop\android-cts-5.0_r2-linux_x86-arm\android-cts\tools\hosttestlib.jar;C:\Users\Desktop\android-cts-5.0_r2-linux_x86-arm\android-cts\tools\ddmlib-prebuilt.jar;C:\Users\Desktop\android-cts-5.0_r2-linux_x86-arm\android-cts\tools\tradefed-prebuilt.jar -DCTS_ROOT=C:\Users\Desktop\android-cts-5.0_r2-linux_x86-arm com.android.cts.tradefed.command.CtsConsole

How to use Android-Libs in JUnit-Test Cases?

I want to use JUNIT for some network classes in my Android-Project. I am using Apache HttpClient which is already included in android. But when I run my junit test it comes to an exception. I included all my lib files in the Junit-Testrunner. But obviously it is not enough because the HttpClient is not found. Does some know what I am doing wrong?
Here is the exception
java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient
at de.srs.android.pdixuploader.network.test.ClientAppTest.testCheckLogin(ClientAppTest.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:243)
at junit.framework.TestSuite.run(TestSuite.java:238)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.ClassNotFoundException: org.apache.http.client.HttpClient
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 19 more
I resolved this by adding the JUnit library to my project:
Open project's Properties > Java Build Path
Open the Libraries tab
Click Add Library
Select JUnit
Click Next
Make sure that the correct version of JUnit is selected in the dropdown
Click Finish

NoClassDefFoundError: com/google/common/base/Predicate when importing MonkeyRunner in Jython

I want to use MonkeyRunner to generate MotionEvent (from screen touch). I have read the info on
http://developer.android.com/guide/developing/tools/monkeyrunner_concepts.html.
The problem is that for this jython program:
from com.android.monkeyrunner import MonkeyRunner
if __name__ == '__main__':
# Connects to the current device, returning a MonkeyDevice object
device = MonkeyRunner.waitForConnection()
I get the following error when executed:
Traceback (most recent call last):
File "C:\Documents and Settings\jjungb00\python\workspace\monkey\src\runner.py", line 6, in <module>
from com.android.monkeyrunner import MonkeyRunner
java.lang.NoClassDefFoundError: com/google/common/base/Predicate
at com.android.monkeyrunner.MonkeyRunner.classDictInit(MonkeyRunner.java:48)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.python.core.PyJavaType.init(PyJavaType.java:534)
at org.python.core.PyType.createType(PyType.java:1264)
at org.python.core.PyType.addFromClass(PyType.java:1201)
at org.python.core.PyType.fromClass(PyType.java:1291)
...
skipping some stack trace
...
Caused by: java.lang.ClassNotFoundException: com.google.common.base.Predicate
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
...
I have added monkeyrunner.jar from the android sdk tool/lib as an external library.
I'm running on XP, with jython 2.5.2.
Any idea what to do? I guess I must add another library, but I do not know where or which.
You need to add the Google Collections library - currently renamed to Guava. Look for guavalib.jar in the android SDK directory.

Categories

Resources