I am having a problem with use of this open source development kit - https://github.com/cdk/cdk
Here is the java code for BasicProgram:
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.Atom;
public class BasicProgram {
public static void main(String args[]) throws Exception {
IAtom atom = new Atom("C");
System.out.println(atom);
}
}
When I go to compile the class file is generated without errors, but doesn't seem to find the references in the jar file:
E:\Cheminformatics>javac -cp cdk-2.0.jar BasicProgram.java
E:\Cheminformatics>java -cp . BasicProgram
Exception in thread "main" java.lang.NoClassDefFoundError: org/openscience/cdk/Atom
at BasicProgram.main(BasicProgram.java:6)
Caused by: java.lang.ClassNotFoundException: org.openscience.cdk.Atom
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)
... 1 more
Related
I have two different Modules: MultiRealm and SurvivalRealm. MultiRealm provides an abstract class (LoadedRealm) which the class SurvivalRealm (in the Module SurvivalRealm) extends. Now, MultiRealm tries to load the SurvivalRealm class from the jar. But when trying to load, i get the Following error: java.lang.NoClassDefFoundError: net/lightbluefoxlabs/dev/multirealm/core/multirealmcore/Realms/LoadedRealm where net/lightbluefoxlabs/dev/multirealm/core/multirealmcore/Realms/LoadedRealm is the correct location of the LoadedRealm class. Here is the Stacktrace:
[23:03:52] [Thread-10/WARN]: at java.lang.ClassLoader.defineClass1(Native Method)
[23:03:52] [Thread-10/WARN]: at java.lang.ClassLoader.defineClass(Unknown Source)
[23:03:52] [Thread-10/WARN]: at java.security.SecureClassLoader.defineClass(Unknown Source)
[23:03:52] [Thread-10/WARN]: at java.net.URLClassLoader.defineClass(Unknown Source)
[23:03:52] [Thread-10/WARN]: at java.net.URLClassLoader.access$100(Unknown Source)
[23:03:52] [Thread-10/WARN]: at java.net.URLClassLoader$1.run(Unknown Source)
[23:03:52] [Thread-10/WARN]: at java.net.URLClassLoader$1.run(Unknown Source)
[23:03:52] [Thread-10/WARN]: at java.security.AccessController.doPrivileged(Native Method)
[23:03:52] [Thread-10/WARN]: at java.net.URLClassLoader.findClass(Unknown Source)
[23:03:52] [Thread-10/WARN]: at java.lang.ClassLoader.loadClass(Unknown Source)
[23:03:52] [Thread-10/WARN]: at java.lang.ClassLoader.loadClass(Unknown Source)
[23:03:52] [Thread-10/WARN]: at net.lightbluefoxlabs.dev.multirealm.core.multirealmcore.Realms.LoadedRealm.RealmFactory(LoadedRealm.java:54)
[23:03:52] [Thread-10/WARN]: at net.lightbluefoxlabs.dev.multirealm.core.multirealmcore.Realms.LoadedRealm.RealmFactory(LoadedRealm.java:20)
[23:03:52] [Thread-10/WARN]: at net.lightbluefoxlabs.dev.multirealm.core.multirealmcore.Realms.RealmManager.Initialize(RealmManager.java:22)
[23:03:52] [Thread-10/WARN]: at net.lightbluefoxlabs.dev.multirealm.core.multirealmcore.Realms.RealmManager.lambda$InitializeAsync$0(RealmManager.java:39)
[23:03:52] [Thread-10/WARN]: at java.lang.Thread.run(Unknown Source)
[23:03:52] [Thread-10/WARN]: Caused by: java.lang.ClassNotFoundException: net.lightbluefoxlabs.dev.multirealm.core.multirealmcore.Realms.LoadedRealm
[23:03:52] [Thread-10/WARN]: at java.net.URLClassLoader.findClass(Unknown Source)
[23:03:52] [Thread-10/WARN]: at java.lang.ClassLoader.loadClass(Unknown Source)
[23:03:52] [Thread-10/WARN]: at java.lang.ClassLoader.loadClass(Unknown Source)
[23:03:52] [Thread-10/WARN]: ... 16 more
Here is the SurvivalRealm class:
import net.lightbluefoxlabs.dev.multirealm.core.multirealmcore.Realms.LoadedRealm;
import net.lightbluefoxlabs.dev.multirealm.core.multirealmcore.Realms.Worlds.RealmWorld;
public class SurvivalRealm extends LoadedRealm {
public SurvivalRealm(String RealmPath) {
super(RealmPath);
Load();
}
#Override
public void Load() {
//LoadStuff
}
#Override
public void Unload() {
}
}
... and this static function in LoadedRealm tries to import this class:
public static LoadedRealm RealmFactory(String jarPath, String RealmPath) throws RealmLoadException{
try {
File file = new File(jarPath);
URLClassLoader c = new URLClassLoader(new URL[]{file.getAbsoluteFile().toURI().toURL()});
Class<?> realmClass = c.loadClass(RealmClass);
return (LoadedRealm)(realmClass.getDeclaredConstructor(String.class).newInstance(RealmPath));
}catch (Exception e){
throw new RealmLoadException(e);
}
}
Here is a picture of the Structure:
The MultiRealm Module does not import/"Know about" (excuse my terminology) the SurvivalRealm module, only the other way around.
Am I just trying to achieve something impossible? If you need the .iml file, just ask. Any help would be really apreciated, I have been trying to fix this issue for basically the whole day now.
Thanks for reading through this beginner issue.
You should try using your pom files from maven for achieve your goal. A multi-module project is defined by a parent POM referencing one or more submodules.
I have a problem during compilation of the program. The code itself has no errors.
Program code:
package plate;
import java.io.File;
import net.sourceforge.tess4j.Tesseract;
public class OcrReader {
public static void main(String[] args) throws Exception {
String inputFilePath = "C:\\Users\\Me\\eclipse-workspace\\platerecognition\\picture.tif";
Tesseract tesseract = new Tesseract();
String fullText = tesseract.doOCR(new File(inputFilePath));
System.out.println(fullText);
}
}
And the error after running the program:
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/jna/Pointer
at plate.OcrReader.main(OcrReader.java:11)
Caused by: java.lang.ClassNotFoundException: com.sun.jna.Pointer
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)
... 1 more
package photo;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import com.github.sarxos.webcam.Webcam;
public class capture {
public static void main(String arg[]) throws IOException {
Webcam webcam = Webcam.getDefault();
webcam.open();
BufferedImage image = webcam.getImage();
ImageIO.write(image, "JPG", new File("test.jpg"));
}
}
I have written this java code to capture photo through webcam, but this code is throwing an error/exception please tell how can I fix it.?
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at com.github.sarxos.webcam.Webcam.<clinit>(Webcam.java:97)
at photo.capture.main(capture.java:12)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
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)
... 2 more
Download SLF4J and put the slf4j-api-1.7.2.jar file onto your class path.
I've been messing around with ClassLoaders in java recently, trying to run my automation script code which uses dynamic loading of classes and geting ClassNotFoundException.
##MyCode
package com.actitime5.frameworkengine;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import com.gmail5.Testcases.LoginLogout;
import org.junit.runner.JUnitCore;
public class Init {
public static void main(String args[]) throws Exception
{
Init in=new Init();
String url=in.getConfigValue("url");
ExcelLibrary lib=new ExcelLibrary();
JUnitCore core = new JUnitCore();
int numberofTestcases=lib.getRowCont("Scenario");
System.out.println(numberofTestcases);
for(int i=1;i<=numberofTestcases;i++)
{String status=lib.getExcelData("Scenario", i, 1);
if(status.equals("yes"))
{String scriptnam=lib.getExcelData("Scenario", i, 0);
System.out.println("Sheet Name"+" "+scriptnam);
Class scriptToRun= Class.forName("com.gmail5.Testcases."+scriptnam);
core.run(scriptToRun);
}
}}
##Errors that i am getting :
1
Sheet Name LoginLogout
Exception in thread "main" java.lang.ClassNotFoundException:com.gmail5.Testcases.LoginLogout
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 java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.gmail5.frameworkengine.Init.main(Init.java:24)
The class which I am trying to load is available in package: com.gmail5.Testcases.*;,but still it throws exception
I think your class name has trailing whitespace. Try trim()ming it off before attempting to load the class.
You can confirm this by replacing
System.out.println("Sheet Name"+" "+scriptnam);
with
System.out.println("Sheet Name"+" '"+scriptnam+"'");
I expect this will print out something like the following:
Sheet Name 'LoginLogout '
When I clicked 'edit' to edit your question, I could see there was trailing whitespace after the class name in the stack trace and in your Sheet Name message. (I didn't change anything in your question: I just used the Edit function to see the raw text of your question, and then clicked Cancel.)
When I generated a Java Client through the web page of wso2esb for a deployed service "Hello". In addition to the HelloServiceCallBackHandler.java and HelloServiceStub.java I created the class entitled HelloClient.java:
package org.wso2.cs.helloservices;
import java.rmi.RemoteException;
import org.wso2.cs.helloservices.HelloServiceStub.SayHello;
import org.wso2.cs.helloservices.HelloServiceStub.SayHelloResponse;
public class HelloClient {
public static void main(String[] args) {
try {
String name= new String("Test");
HelloServiceStub stub= new HelloServiceStub();
SayHello sh= new SayHello();
sh.setName(name);
SayHelloResponse resp=stub.sayHello(sh);
System.out.println("Response : "+resp);
}catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
I have the following error:
<font color="red"> Exception in thread "main" java.lang.NoClassDefFoundError: javax/wsdl/extensions/soap/SOAPAddress
at org.wso2.cs.helloservices.HelloServiceStub.populateAxisService(HelloServiceStub.java:41)
at org.wso2.cs.helloservices.HelloServiceStub.<init>(HelloServiceStub.java:88)
at org.wso2.cs.helloservices.HelloServiceStub.<init>(HelloServiceStub.java:77)
at org.wso2.cs.helloservices.HelloServiceStub.<init>(HelloServiceStub.java:126)
at org.wso2.cs.helloservices.HelloServiceStub.<init>(HelloServiceStub.java:118)
at org.wso2.cs.helloservices.HelloClient.main(HelloClient.java:13)
Caused by: java.lang.ClassNotFoundException: javax.wsdl.extensions.soap.SOAPAddress
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)
... 6 more</font>
This seems to be required jars not found (This complains about wsld4j). Please add AXIS2_HOME/lib folder to your program's classpath .