简体   繁体   English

为什么会收到ClassNotFoundException?

[英]Why am I geting a ClassNotFoundException?

Using Ubuntu 使用Ubuntu

Here is my code: 这是我的代码:

import java.io.*;
import java.net.*;
import se.opendataexchange.ethernetip4j.clx.*;

class PLCServer
{
    public static void main(String argv[]) throws IOException
    {
        // IP address of the ethernet card
        String ENBTIP = "192.168.10.14";
        DataInputStream socketReader = null;
        PrintStream socketWriter = null;
        ControlLogixConnector test = new ControlLogixConnector(ENBTIP,44818);

        // Debugging code
        System.out.println(InetAddress.getByName(ENBTIP).isReachable(10000));
    }
}

Here is how I am compiling: 这是我的编译方式:

javac -classpath /home/nick/Java/PLC/ethernetip4j-0.2.jar PLCServer.java which returns no errors javac -classpath /home/nick/Java/PLC/ethernetip4j-0.2.jar PLCServer.java ,不返回任何错误

Here is the output: 这是输出:

Exception in thread "main" java.lang.NoClassDefFoundError: se/opendataexchange/ethernetip4j/clx/ControlLogixConnector
    at PLCServer.main(PLCServer.java:13)
Caused by: java.lang.ClassNotFoundException: se.opendataexchange.ethernetip4j.clx.ControlLogixConnector
    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)
    ... 1 more

Am I missing something here? 我在这里想念什么吗?

Make sure you're also specifying the classpath when running your code. 确保在运行代码时也指定了类路径。 If you're still having issues after adding everything you need to the java classpath, check that those missing classes are actually in the jars/locations you are specifying. 如果将所需的所有内容添加到java类路径后仍然存在问题,请检查那些缺少的类是否确实在您指定的jar /位置中。 Also you can enable some debug flags to give more information on class loading, etc. 您还可以启用一些调试标志,以提供有关类加载等的更多信息。

So for example... 例如

java -classpath /home/nick/Java/PLC/ethernetip4j-0.2.jar:. PLCServer

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我使用while(in.hasNext())从键盘获取值 - Why am i geting the value from keyboard with while( in.hasNext() ) 为什么在Java应用程序中收到ClassNotFoundException? - Why am I getting a ClassNotFoundException in a java application? 为什么我收到NoClassDefFoundError / ClassNotFoundException - Why am I getting NoClassDefFoundError / ClassNotFoundException 为什么我用ObjectInputStream.readObject()得到ClassNotFoundException? - Why am I getting ClassNotFoundException with ObjectInputStream.readObject()? 为什么会出现错误“ java.lang.ClassNotFoundException”? - Why am I getting an error “java.lang.ClassNotFoundException”? 为什么我收到java.lang.ClassNotFoundException? - Why am I getting a java.lang.ClassNotFoundException? 我在 Android 中面临 ClassNotFoundException - I am facing ClassNotFoundException in Android 有没有办法摆脱我得到的这个空指针异常? - Is there a way to get rid of this null pointer exception I am geting? 为什么我的项目中出现“ java.lang.ClassNotFoundException”错误 - why am I getting “java.lang.ClassNotFoundException” error in my project 负载:找不到类MyApplet:java.lang.ClassNotFoundException。 包中有类文件时,为什么会得到这个? - load: class MyApplet not found : java.lang.ClassNotFoundException. Why am i getting this,when the class file is there in the package?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM