For a tests reason I am trying locally to use EmbeddedSolrSolver (I know it's deprected it's only for tests).
I was fallowing this example
http://balabtech.wordpress.com/2011/10/13/embedded-solr-server-using-java/
and the official wiki as well
http://wiki.apache.org/solr/Solrj
I am still gettinga an error
java.lang.NoClassDefFoundError: org/apache/solr/common/ResourceLoader
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:787)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:447)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
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:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at org.apache.solr.core.CoreContainer$Initializer.initialize(CoreContainer.java:111)
at pl.psnc.dl.wf4ever.searchserver.solr.SolrSearchConfigTest.testCos(SolrSearchConfigTest.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
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: org.apache.solr.common.ResourceLoader
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:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 37 more
Is anyone familiar with this exception?
Cheers
Solved, seems solrj in version > 4 isn't compatible with solr-core version < 4. Thx a lot.
Download the jar containing the class ResourceLoader from this link., taking the version that suits you.
NoClassDefFoundError and ClassNotFoundException are thrown when a required class is not found on the classpath. Add the jar you downloaded on the classpath.
Related
We are developing unit test for a Java App that depends on an external jar. We use JMockit, and the unit test can run successfully. Then we enable JMockit code coverage. Then the Jmockit code coverage code somehow calls into the static initialization code of a class in the external jar. Since that class is not supposed to run in a test env, this causes an exception. Note that
1. The unit test can run successfully if code coverage is not enabled
2. The stack trace shows nothing of the class we are testing, it comes from the JMockit code (mockit.coverage.CodeCoverage.transform) to the static initialization of the third party class.
3. This is an external class in a jar, jmockit is not supposed to do code coverage about it according to the document, right? Does mockit.coverage.modification.ClassModification.modifyClassForCoverage mean instrumenting the code?
4. We tried -Djmockit-codecoverage-excludes flag, and it did not help.
Is this a bug of JMockit code coverage?
================ stack trace of error ============================
at THE_THIRD_PARTY_EXTERNAL_CLASS.<clinit>(THE_THIRD_PARTY_EXTERNAL_CLASS.java:line_number)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at mockit.internal.util.ClassLoad.loadClass(ClassLoad.java:102)
at mockit.internal.util.ClassLoad.loadClass(ClassLoad.java:54)
at mockit.internal.util.ClassLoad.loadByInternalName(ClassLoad.java:31)
at mockit.internal.util.ClassLoad.getSuperClass(ClassLoad.java:146)
at mockit.internal.util.ClassLoad.actualSuperClass(ClassLoad.java:177)
at mockit.internal.util.ClassLoad.whichIsSuperClass(ClassLoad.java:167)
at mockit.external.asm.ClassWriter.getCommonSuperClass(ClassWriter.java:1694)
at mockit.external.asm.ClassWriter.getMergedType(ClassWriter.java:1661)
at mockit.external.asm.Frame.merge(Frame.java:1426)
at mockit.external.asm.Frame.merge(Frame.java:1325)
at mockit.external.asm.MethodWriter.visitMaxs(MethodWriter.java:1475)
at mockit.external.asm.MethodVisitor.visitMaxs(MethodVisitor.java:804)
at mockit.external.asm.ClassReader.readCode(ClassReader.java:1554)
at mockit.external.asm.ClassReader.readMethod(ClassReader.java:1017)
at mockit.external.asm.ClassReader.accept(ClassReader.java:693)
at mockit.external.asm.ClassReader.accept(ClassReader.java:506)
at mockit.coverage.modification.ClassModification.modifyClassForCoverage(ClassModification.java:142)
at mockit.coverage.modification.ClassModification.modifyClassForCoverage(ClassModification.java:217)
at mockit.coverage.modification.ClassModification.modifyClass(ClassModification.java:192)
at mockit.coverage.CodeCoverage.transform(CodeCoverage.java:127)
at sun.instrument.TransformerManager.transform(TransformerManager.java:188)
at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:424)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
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:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2442)
at java.lang.Class.getDeclaredMethods(Class.java:1808)
at org.junit.runners.model.TestClass.<init>(TestClass.java:38)
at org.junit.runners.ParentRunner.<init>(ParentRunner.java:65)
at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:59)
at mockit.integration.junit4.JMockit.<init>(JMockit.java:30)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:31)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:24)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:33)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:48)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38)
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)
I'm using play-1.2.5. For async I'm using await() method in my controller. but that await() causing IncompatibleClassChangeError during my application startup. I really don't understand the reason.
when I comment await() line, that error gone away.
here is my Contoller action:
public static void loadScheduledConfigs() {
Future<JsonObject> future = Startup.THREAD_POOL.submit(new MyCallable());
JsonObject object = null;
/*
I also tried this
Future<JsonObject> future = new FutureTask<JsonObject>( new MyCallable());
JsonObject object = await(future);
*/
try{
object = future.get();
}catch(Exception e) {
log.error(e.getMessage(), e);
}
renderJSON(object);
}
Exception:
Oops: IncompatibleClassChangeError
An unexpected error occured caused by exception IncompatibleClassChangeError: Implementing class
play.exceptions.UnexpectedException: Unexpected Error
at play.Invoker$Invocation.onException(Invoker.java:244) ~[play-1.2.5rc4.jar:na]
at play.Invoker$Invocation.run(Invoker.java:286) ~[play-1.2.5rc4.jar:na]
at Invocation.HTTP Request(Play!) ~[na:na]
Caused by: java.lang.IncompatibleClassChangeError: Implementing class
at java.lang.ClassLoader.defineClass1(Native Method) ~[na:1.7.0_07]
at java.lang.ClassLoader.defineClass(ClassLoader.java:791) ~[na:1.7.0_07]
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) ~[na:1.7.0_07]
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449) ~[na:1.7.0_07]
at java.net.URLClassLoader.access$100(URLClassLoader.java:71) ~[na:1.7.0_07]
at java.net.URLClassLoader$1.run(URLClassLoader.java:361) ~[na:1.7.0_07]
at java.net.URLClassLoader$1.run(URLClassLoader.java:355) ~[na:1.7.0_07]
at java.security.AccessController.doPrivileged(Native Method) ~[na:1.7.0_07]
at java.net.URLClassLoader.findClass(URLClassLoader.java:354) ~[na:1.7.0_07]
at java.lang.ClassLoader.loadClass(ClassLoader.java:423) ~[na:1.7.0_07]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) ~[na:1.7.0_07]
at java.lang.ClassLoader.loadClass(ClassLoader.java:356) ~[na:1.7.0_07]
at java.lang.ClassLoader.defineClass1(Native Method) ~[na:1.7.0_07]
at java.lang.ClassLoader.defineClass(ClassLoader.java:791) ~[na:1.7.0_07]
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) ~[na:1.7.0_07]
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449) ~[na:1.7.0_07]
at java.net.URLClassLoader.access$100(URLClassLoader.java:71) ~[na:1.7.0_07]
at java.net.URLClassLoader$1.run(URLClassLoader.java:361) ~[na:1.7.0_07]
at java.net.URLClassLoader$1.run(URLClassLoader.java:355) ~[na:1.7.0_07]
at java.security.AccessController.doPrivileged(Native Method) ~[na:1.7.0_07]
at java.net.URLClassLoader.findClass(URLClassLoader.java:354) ~[na:1.7.0_07]
at java.lang.ClassLoader.loadClass(ClassLoader.java:423) ~[na:1.7.0_07]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) ~[na:1.7.0_07]
at java.lang.ClassLoader.loadClass(ClassLoader.java:356) ~[na:1.7.0_07]
at play.classloading.enhancers.ContinuationEnhancer.enhanceThisClass(ContinuationEnhancer.java:74) ~[play-1.2.5rc4.jar:na]
at play.CorePlugin.enhance(CorePlugin.java:297) ~[play-1.2.5rc4.jar:na]
at play.plugins.PluginCollection.enhance(PluginCollection.java:551) ~[play-1.2.5rc4.jar:na]
at play.classloading.ApplicationClasses$ApplicationClass.enhance(ApplicationClasses.java:235) ~[play-1.2.5rc4.jar:na]
at play.classloading.ApplicationClassloader.loadApplicationClass(ApplicationClassloader.java:167) ~[play-1.2.5rc4.jar:na]
at play.classloading.ApplicationClassloader.getAllClasses(ApplicationClassloader.java:431) ~[play-1.2.5rc4.jar:na]
at play.Play.start(Play.java:516) ~[play-1.2.5rc4.jar:na]
at play.Play.detectChanges(Play.java:642) ~[play-1.2.5rc4.jar:na]
at play.Invoker$Invocation.init(Invoker.java:198) ~[play-1.2.5rc4.jar:na]
... 1 common frames omitted
I don't know either problem is in the way I code, or some dependencies comflict causing this issue. (I checked my lib folder and classpath/dependencies of my project, I did not find any conflicting library)
I got the solution. it's asm.jar who was creating issue. I'm using kryo for serialization. kryo and play both has asm.jar as a dependency. So i have two different version of asm.jar in my class path. one that comes with kryo and other one that comes with play framework. that was causing issue.
I removed one asm.jar and that exception gone away.
I have a java application that uses the Arquillian library for testing. I am attempting to now add the Arquillian reporter extension. As shown in the documentation at https://github.com/arquillian/arquillian-recorder/wiki/Reporter, I have added the dependency to my pom.
<dependency>
<groupId>org.arquillian.extension</groupId>
<artifactId>arquillian-recorder-reporter-impl</artifactId>
<version>1.0.0.Final</version>
</dependency>
However, now when I build my project, which worked before adding this new dependency, I get the error shown below.
java.lang.RuntimeException: Could not create new instance of class org.jboss.arquillian.test.impl.EventTestRunnerAdaptor
at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:160)
at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:111)
at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:97)
at org.jboss.arquillian.test.spi.TestRunnerAdaptorBuilder.build(TestRunnerAdaptorBuilder.java:52)
at org.jboss.arquillian.testng.Arquillian.arquillianBeforeSuite(Arquillian.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:543)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:212)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:277)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:87)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1137)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1062)
at org.testng.TestNG.run(TestNG.java:974)
at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:69)
at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeMulti(TestNGDirectoryTestSuite.java:181)
at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:99)
at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:113)
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:200)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:153)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
....
Caused by: java.lang.ClassNotFoundException: org.jboss.arquillian.test.spi.event.suite.BeforeTestLifecycleEvent
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)
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2570)
at java.lang.Class.getDeclaredMethods(Class.java:1855)
at org.jboss.arquillian.core.impl.Reflections.getObserverMethods(Reflections.java:52)
at org.jboss.arquillian.core.impl.ExtensionImpl.of(ExtensionImpl.java:51)
at org.jboss.arquillian.core.impl.ManagerImpl.createExtensions(ManagerImpl.java:440)
at org.jboss.arquillian.core.impl.ManagerImpl.fireProcessing(ManagerImpl.java:375)
at org.jboss.arquillian.core.impl.ManagerImpl.<init>(ManagerImpl.java:100)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.jboss.arquillian.core.spi.SecurityActions.newInstance(SecurityActions.java:156)
at org.jboss.arquillian.core.spi.SecurityActions.newInstance(SecurityActions.java:111)
at org.jboss.arquillian.core.spi.SecurityActions.newInstance(SecurityActions.java:97)
at org.jboss.arquillian.core.spi.ManagerBuilder.create(ManagerBuilder.java:77)
at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.<init>(EventTestRunnerAdaptor.java:55)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:156)
at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:111)
at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:97)
at org.jboss.arquillian.test.spi.TestRunnerAdaptorBuilder.build(TestRunnerAdaptorBuilder.java:52)
at org.jboss.arquillian.testng.Arquillian.arquillianBeforeSuite(Arquillian.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:543)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:212)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
This is caused by a conflict between different versions of Arquillian. This error is resolved by updating from 1.1.5.Final to:
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>1.1.8.Final</version>
<scope>import</scope>
<type>pom</type>
</dependency>
The Arquillian version needs to be updated to support the recorder.
I am writing an android app but using JUnit to test it out some of the more java-specific functionality before creating activities and the android-specific functions. As I write out the JUnit tests and execute them bit by bit, I am finding failures at the line dbHelper = new DatabaseSystemHelper(context, null, null, 0);
public DatabaseSystem(Context context) {
dbHelper = new DatabaseSystemHelper(context, null, null, 0);
database = dbHelper.getWritableDatabase();
}
class DatabaseSystemHelper extends SQLiteOpenHelper {
...
DatabaseSystemHelper(Context context, String name, CursorFactory factory, int version) {
super(context, name, factory, version);
setDatabaseValues(context);
}
**java.lang.NoClassDefFoundError: android/database/sqlite/SQLiteOpenHelper**
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
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)
at edu.project2.systems.DatabaseSystem.<init>(DatabaseSystem.java:58)
at edu.project2.systems.DatabaseSystem$SingletonHolder.<clinit>(DatabaseSystem.java:193)
at edu.project2.systems.DatabaseSystem.getInstance(DatabaseSystem.java:203)
at edu.project2.systems.DatabaseSystemTest.setUp(DatabaseSystemTest.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
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.database.sqlite.SQLiteOpenHelper
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)
... 42 more
I am at a bit of a loss. It seems that my code never gets past the line for making a new DatabaseHelper object. In fact, when I "step-into" the call, the debug cursor never even gets into the constructor. Any advice would be great
Please make sure the class SQLiteOpenHelper is available to the JVM at runtime.
The NoClassDefFoundError usually occurs when a class needed to compile the project is present during build time but missing during run time.
Ensure the class is included both in the build path and the classpath.
I got the tests to work by creating a separate Android Test Project and making my classes extend the AnroidTestCase class. https://developer.android.com/tools/testing/index.html
I know this answer isn't fully fleshed out, but in short it seems that you cannot use POJO's or run the regular JUnit/JVM when you are dealing with android specific classes since those classes need the Android emulator/devise to run on.
Here is what my test class looks like (keeping in my that it running in the android VM)
import android.content.Context;
import android.test.AndroidTestCase;
public class DatabaseSystemsTest extends AndroidTestCase {
private DatabaseSystem dbSystem;
#Override
protected void setUp() throws Exception {
super.setUp();
Context context = getContext();
DatabaseSystem.setContext(context);
dbSystem = DatabaseSystem.getInstance();
dbSystem.getDbHelper().onCreate(dbSystem.getDatabase());
} // end of setUp() method definition
}
I'm new to writing the Struts 2 test cases. And while running the test case I'm getting this error
java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/servlet/jsp/PageContext
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
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:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
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:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at org.apache.struts2.StrutsTestCase.initServletMockObjects(StrutsTestCase.java:225)
at org.apache.struts2.StrutsTestCase.setUp(StrutsTestCase.java:207)
at junit.framework.TestCase.runBare(TestCase.java:132)
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.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
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)
If you are using JUnit4 to run tests then you should use StrutsJUnit4TestCase instead of StrutsTestCase.