线程“main”中的异常java.lang.NoClassDefFoundError:名称错误 [英] Exception in thread "main" java.lang.NoClassDefFoundError: wrong name

查看:206
本文介绍了线程“main”中的异常java.lang.NoClassDefFoundError:名称错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的文件目录:

project/src/m2mcom/entities/AutomatedTelnetClient.java
           /web/Simple.java           
           /org/apache/commons/net/telnet/TelnetClient.java 

Simple.java的源代码:

The source code of the Simple.java:

package m2mcom.web;
import m2mcom.entities.AutomatedTelnetClient;
import java.util.*;
import java.io.*;

public class Simple {
    public static void main(String [] args) {
        try {
            AutomatedTelnetClient telnet = new AutomatedTelnetClient();
            String answer = telnet.request();
            System.out.println(answer);
        } catch (Exception e) {
            System.err.println("Error");
        }
    }
}

当我执行Simple时。类,没有任何编译错误,我收到此错误消息:

And when I execute Simple.class, without any errors of compilation, I get this error message:

C:\Users\Victor\Desktop\project2\src\m2mcom\web>java Simple
Exception in thread "main" java.lang.NoClassDefFoundError: Simple (wrong name: m
2mcom/web/Simple)

有谁知道如何解决这个问题?

Does anyone know how to solve this?

推荐答案

您正在错误的文件夹中执行命令,并使用错误的类名。运行Java类时,需要使用完全限定名称(FQN)。当然,你必须在正确的目录中。在您的示例中,您的类的FQN是m2mcom.web.Simple( m2mcom.web 的组合和简单 name 简单)。

You're executing the command in the wrong folder, with the wrong classname. You need to use the fully qualified name (FQN) when running a Java class. And of course, you have to be in the right directory. In your example, the FQN of your class is m2mcom.web.Simple (combination of the package m2mcom.web and the simple name Simple).

就推断正确的目录而言,您的类存储在分层文件夹结构中,该结构基本上以 C:\ Users \开头Victor\Desktop\project2\src

As far as deducing the right directory, your classes are stored in a hierarchical folder structure, which basically starts in C:\Users\Victor\Desktop\project2\src.

所以要正确执行你的程序,从 C:\\ \\ Users\Victor \Desktop\project2\src ,do;

So to correctly execute your program, from C:\Users\Victor\Desktop\project2\src, do;

java m2mcom.web.Simple

这篇关于线程“main”中的异常java.lang.NoClassDefFoundError:名称错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆