I write a project in Android studio 2.3.3, I have JUnit test, also I use Jenkins as CI. My tasks in CI are clean,testDevDebugUnitTest. In past, my tests were working fine. Yesterday I removed folder build from my Android project and after that testDevDebugUnitTest always failed in CI.but In Android studio all is ok.
Stacktrace I am getting is as below:
java.lang.NoClassDefFoundError: android/os/Parcelable
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at ru.alfabank.oavdo.amc.base.models.Amount$Parser.parse(Amount.kt:135)
at ru.alfabank.oavdo.amc.base.models.Amount$Parser.parse(Amount.kt:114)
at ru.alfabank.oavdo.amc.base.models.AmountTest.parseTest(AmountTest.kt:78)
Caused by:
java.lang.ClassNotFoundException: android.os.Parcelable
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 15 more
I googled about this and found almost nothing, except that remove gradle folder, but after that project doesn't compile. Maybe anyone met this problem?
Make your model class implements with Serializable.
Related
I have a series of tests separated into classes. The tests run properly when run individually or when run as a whole package. Most classes also run properly when executed as a class, but there is one class that fails to execute with the following error:
java.lang.RuntimeException: Delegate runner 'org.robolectric.RobolectricTestRunner' for AndroidJUnit4 could not be loaded.
at androidx.test.ext.junit.runners.AndroidJUnit4.throwInitializationError(AndroidJUnit4.java:92)
at androidx.test.ext.junit.runners.AndroidJUnit4.loadRunner(AndroidJUnit4.java:82)
at androidx.test.ext.junit.runners.AndroidJUnit4.loadRunner(AndroidJUnit4.java:51)
at androidx.test.ext.junit.runners.AndroidJUnit4.<init>(AndroidJUnit4.java:46)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:49)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at androidx.test.ext.junit.runners.AndroidJUnit4.loadRunner(AndroidJUnit4.java:72)
... 16 more
Caused by: java.lang.NoClassDefFoundError: androidx/test/rule/ActivityTestRule
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.getDeclaredMethods(Class.java:1975)
at org.junit.internal.MethodSorter.getDeclaredMethods(MethodSorter.java:54)
at org.junit.runners.model.TestClass.scanAnnotatedMembers(TestClass.java:65)
at org.junit.runners.model.TestClass.<init>(TestClass.java:57)
at org.junit.runners.ParentRunner.createTestClass(ParentRunner.java:88)
at org.junit.runners.ParentRunner.<init>(ParentRunner.java:83)
at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:65)
at org.robolectric.internal.SandboxTestRunner.<init>(SandboxTestRunner.java:56)
at org.robolectric.RobolectricTestRunner.<init>(RobolectricTestRunner.java:92)
... 21 more
Caused by: java.lang.ClassNotFoundException: androidx.test.rule.ActivityTestRule
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:419)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
... 32 more
The problem only appears in this specific class and when the tests are run on the class, not individually or as a package.
I have verified that only androidx libraries are being used, that rules are setup properly and that the roboelectric dependency is included as per other answers in this forum.
Has anyone had a similar problem or has any suggestions to fix this issue?
Note: I have tried recreating the issue in a small example code, but haven't been able to. I also can't post the code that fails due to proprietary reasons.
The problem was due to having public methods in the test class that were not annotated with #Test. The solution I used was adding #Ignore and #Test annotations to the method. ie:
#Ignore #Test fun someUnImplementedTest() { }
Adding only #Test works as well, but it will run the test and mark it as passed allowing you to forget that it's not yet implemented.
Just downloaded Android Studio Canary Build: 2.2 Preview 6, on trying to start I get:
Internal Error. Please report to https://code.google.com/p/android/issues
com.intellij.ide.plugins.PluginManager$StartupAbortedException: java.lang.reflect.InvocationTargetException
at com.intellij.ide.plugins.PluginManager$2.run(PluginManager.java:96)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.ide.plugins.PluginManager$2.run(PluginManager.java:93)
... 1 more
Caused by: java.lang.NoClassDefFoundError: org/apache/log4j/Layout
at com.intellij.idea.MainImpl.start(MainImpl.java:34)
... 6 more
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Layout
at com.intellij.util.lang.UrlClassLoader.findClass(UrlClassLoader.java:207)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
I've googled and not been able to find any fixes.
I'm running Linux Mint Rebecca 17.1 32-bit.
Not sure what other information to provide. Any help is appreciated, thanks.
just install the jdk1.8.0_102 and set JAVA_PATH in your Environment Variable to C:\Program Files\Java\jdk1.8.0_102
I must have messed up installation somehow, after deleting ~/.AndroidStudioPreview1.2/ and ~/.AndroidStudioPreview2.2/ I redownloaded the installation zip and reinstalled. Now it seems to be working.
When I try to run my test it gives me this error
Exception in thread "main" java.lang.NoClassDefFoundError: junit/textui/ResultPrinter
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:260)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:116)
Caused by: java.lang.ClassNotFoundException: junit.textui.ResultPrinter
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
Process finished with exit code 1
I tried most of solution that I could find online but nothing helped to fix and it gets really annoying. Any tips to fix that ?
I am using ubuntu 14.04 LTS to build android using command line. However after I open emulator, trying to open ddms. I got the following error message
09:36:10 E/ddms: shutting down due to uncaught exception 09:36:10
E/ddms: org/eclipse/jface/util/IPropertyChangeListener
java.lang.NoClassDefFoundError:
org/eclipse/jface/util/IPropertyChangeListener at
com.android.ddms.Main.main(Main.java:74) Caused by:
java.lang.ClassNotFoundException:
org.eclipse.jface.util.IPropertyChangeListener at
java.net.URLClassLoader$1.run(URLClassLoader.java:366) at
java.net.URLClassLoader$1.run(URLClassLoader.java:355) at
java.security.AccessController.doPrivileged(Native Method) at
java.net.URLClassLoader.findClass(URLClassLoader.java:354) at
java.lang.ClassLoader.loadClass(ClassLoader.java:425) at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at
java.lang.ClassLoader.loadClass(ClassLoader.java:358) ... 1 more
It seems that there is a class not being found. But I am not sure what exactly it means.
After searching, I found it may be wrong ANDROID_SWT. However after I check, there still exist the same problem.
Any idea can help! Thx!
I've got this peculiar issue while testing for an android project via a test project.
The test project runs on the emulator but does not run on the device. It shows the following error on the device:
"java.lang.NoClassDefFoundError: android/test/ActivityInstrumentationTestCase2
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunner.java:693)
at o rg.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(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
... 17 more"
Why do I get java.lang.NoClassDefFoundError: android/test/ActivityInstrumentationTestCase2?