JAVA package 问题记录

遇到的问题:在/..../list/DList.java
compile已过。DList.java 属于 package list
报错: javaDList

Exception in thread "main" java.lang.NoClassDefFoundError: DList(wrong name: list/DList)

at java.lang.ClassLoader.defineClass1(Native Method)

at java.lang.ClassLoader.defineClass(ClassLoader.java:800)

atjava.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)

atsun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)

at java.lang.ClassLoader.loadClass(ClassLoader.java:358)

atsun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)


解决方案:退出list文件夹,然后 java list.DList,成功

参考:from stack Overflow

My file directory:

project/src/m2mcom/entities/AutomatedTelnetClient.java
           /web/Simple.java           
           /org/apache/commons/net/telnet/TelnetClient.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");
        }
    }
}

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?

asked  Jan25 '13 at 11:23
vicesbur
35 1 1 6
 
    
Have a look at this link you will understand why you get that errorand how to avoid it in the futurejavarevisited.blogspot.co.uk/2011/06/…  –    Razh  Jan25 '13 at 11:33
add comment

3 Answers

You're executing the command in the wrong folder, with the wrongclassname. You need to use the fully qualified name (FQN) whenrunning a Java class. And of course, you have to be in the rightdirectory. In your example, the FQN of your class ism2mcom.web.Simple (combination ofthe package m2mcom.webandthe simple name Simple).

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

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

java m2mcom.web.Simple




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值