在Linux下用JDK编译一个java文件报的错。
多谢了!

解决方案 »

  1.   

    没有找到类定义。你的JAVA_HOME环境变量或者classpath没有设。
      

  2.   

    不好意思,不是编译时出错,是运行时出错,而且是找不到本身,即执行A.class文件,找不到A这个类!
    环境变量都设好了的。
      

  3.   

    no definition of the class could be found.
      

  4.   

    如果环境变量设得没有错误的话,那么有可能的错误就是大小写错了,仔细检查一下
    一般出现NoClassDefFoundError错误都不是程序本身的问题
      

  5.   

    你要把你的当前路径指定到Classpath里面去,而且如果你的java文件如果第一行指定了package,你还需要把.class文件放到对应的文件夹中
      

  6.   

    这个错误的意思是知道了,但问题还是没解决。
    以下是源代码,各位帮忙看看。
    public class Ldif2Ldap {
        public static void main( String[] args ) {        if (args.length != 4) {
                usage();
            }        int changeType, version = 1;
            int ldapPort = LDAPConnection.DEFAULT_PORT;
            int ldapVersion  = LDAPConnection.LDAP_V3;
            String fileName = args[0];
            String ldapHost = args[1];
            String loginDN  = args[2];
            String password = args[3];
            LDIFReader reader = null;
            LDAPEntry entry;
            LDAPMessage msg, retMsg;
            Ldif2Ldap readerTest = new Ldif2Ldap();
            LDAPConnection lc = new LDAPConnection();        try {
                FileInputStream fis = new FileInputStream( fileName);
                reader = new LDIFReader(fis, version);
            }
            catch (Exception e) {
                System.err.println("\nFailed to read LDIF file " + fileName +
                                   ", " + e.toString());
                System.exit (1);
            }        try {
                // connect to the server
                lc.connect( ldapHost, ldapPort );
                // bind to the server
                lc.bind( ldapVersion, loginDN, password );            if (!reader.isRequest()) {
                    System.out.println("\nLDIF content file\n");                while ( (msg = reader.readMessage()) != null) {
                        entry = ((LDAPSearchResult)msg).getEntry();
                        System.out.println("\nEntry DN:" + entry.getDN());
                        readerTest.showAttributes(entry);
                    }
                }
                else {
                    System.out.println("\nLDIF change file\n");                while ( (msg = reader.readMessage()) != null) {
                        if (msg instanceof LDAPAddRequest) {
                           System.out.println("Adding entry...");
                        }
                        else if (msg instanceof LDAPDeleteRequest) {
                            System.out.println("Deleting entry...");
                        }
                        else if (msg instanceof LDAPModifyDNRequest) {
                            System.out.println("Modifying entry's RDN...");
                        }
                        else if (msg instanceof LDAPModifyRequest) {
                            System.out.println("Modifying entry's attribute(s)...");
                        }                    LDAPMessageQueue queue = lc.sendRequest(msg, null, null);
                        if ((retMsg = queue.getResponse()) != null) {
                            LDAPResponse response = (LDAPResponse)retMsg;
                            int status = response.getResultCode();                        // the return code is LDAP success
                            if ( status == LDAPException.SUCCESS ) {
                                System.out.println("Directory information has been"
                                                                   + " modified.");
                            }
                            // the reutrn code is referral exception
                            else if ( status == LDAPException.REFERRAL ) {
                                String urls[]=((LDAPResponse)retMsg).getReferrals();
                                System.out.println("Referrals:");
                                for ( int i = 0; i < urls.length; i++ )
                                    System.out.println("    " + urls[i]);
                            }
                            // general error
                            else {
                                System.out.println( response.getErrorMessage());
                            }
                        }
                        System.out.println();
                    }
                }
            }
            catch ( IOException ioe ) {
                System.out.println("Error: " + ioe.toString() );
                System.exit( 1 );
            }
            catch ( LDAPException le ) {
                System.out.println("Error: " + le.toString() );
                System.exit( 1 );
            }        System.exit (0);
        }    public static void usage() {
            System.err.println("Usage:   java Lidf2Ldap <in file name> "
                    + "<host name> <login dn> <password>");
            System.err.println("Example: java Lidf2Ldap inFile Acme.com "
                                        + " \"cn=admin,o=Acme\" secret");
            System.exit(1);
        }    public void showAttributes(LDAPEntry entry) {        String value;
            LDAPAttributeSet as = null;
            LDAPAttribute[]  attrs = null;
            LDAPAttribute attr = null;
            Iterator allAttrs;
            Enumeration allAttrValues;        as = entry.getAttributeSet();
            allAttrs = as.iterator();
            System.out.println("    Attributes:");
            while(allAttrs.hasNext()) {
                attr = (LDAPAttribute)allAttrs.next();
                System.out.println("        " + attr.getName());
                allAttrValues = attr.getStringValues();
                if( allAttrValues != null) {
                    while(allAttrValues.hasMoreElements()) {
                        value = (String) allAttrValues.nextElement();
                        System.out.println("            " + value);
                    }
                }
            }
        }
    }
      

  7.   

    请注意语句Ldif2Ldap readerTest = new Ldif2Ldap(),在这里声明了自身类的一个对象,怀疑是这里的问题。
    环境变量什么的都绝对没问题!
      

  8.   

    错误信息如下:
    Exception in thread "main" java.lang.NoClassDefFoundError:Ldif2Ldap
      

  9.   

    我也遇到了这样的问题,在windowsxp下,刚装的j2sdk1.4.1_01,classpath=.;D:\j2sdk1.4.1_01\lib\dt.jar;D:\j2sdk1.4.1_01\lib\tools.jar;
    java_home=D:\j2sdk1.4.1_01运行demo下的程序没问题,但很简单的程序都会运行报错,
    Exception in thread "main" java.lang.NoClassDefFoundError: test/class怎么搞得???????
      

  10.   

    1.是否在classpath里面设置了".",为当前目录
    2.是否使用了包的概念!如果使用了包要将包所在的目录设为classpath,运行的时候要写上包的路径。例如 java mypackage.com.cn.myjava
      

  11.   

    你不要敲成java test.class,不要.class扩展名的,直接java test就行了!
      

  12.   

    程序不是我的,那人说在Windows的JBuilder下运行没错
    他在Linux下用-cp设了环境变量,是不是用-cp设环境变量不行啊?
      

  13.   

    这种问题在本版中有100个人问,不是程序本身的问题,是配置不正确
    以win2000Professional为例,环境配置:假设前提:你的jdk1.4正确安装在C盘的根目录下,
    正确配置:"我的电脑"-->"属性"-->"高级"-->"环境变量"-->"系统变量"-->如果没有,则进行新建:变量名:Path   变量值:C:\jdk1.4\bin
         变量名:ClassPath    变量值:.;C:\jdk1.4\lib\dt.jar;C;\jdk1.4\lib\tools.jar(注意符号.)
    再创建一个"用户变量"  变量名:JAVA_HOME   变量值:C:\jdk1.4
    这样一来,如果程序正确,在任何地方进行编译,运行都没有问题
      

  14.   

    楼上的老兄,windows下的环境变量我会配置,问题是这个是在Linux下啊,只能通过在java命令后加-cp之类的参数设置,就是不知道是不是用-cp配置的
      

  15.   

    老兄怎么指定 我的文件的目录呢
    c:\java
      

  16.   

    问题原因是知道了,在Linux下,不能在命令行通过-cp来设置环境变量
    ft,还是环境变量的问题!
    多谢各位了!
      

  17.   

    我刚刚也出现这样的错误  我的是因为classpath设置错误