运行简单的Java程序时出现NOClassDefFound错误 [英] NOClassDefFound error while running a simple java program

查看:1248
本文介绍了运行简单的Java程序时出现NOClassDefFound错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码可以很好地编译,但是每当我尝试运行时,都会显示NoClassDefFound错误.请问可能的原因和解决方法.

This code is compile fine, but whenever I try to run, it gives an error says NoClassDefFound. What is the possible reason and solution, please explain.

package myPack;

public class PasswordVerification
{
    public boolean verify(String usrId, String pass)
    {
        if(usrId.equals("pranjut")&&pass.equals("password"))
        {
            return true;
        }else
        {
            return false;
        }
    }

    public static void main(String [] main)
    {
         PasswordVerification vp=new PasswordVerification();
         System.out.println(vp.verify("pranjut","password"));
    }

}

推荐答案

确保您位于包含myPack文件夹的目录中.您不应位于myPack文件夹中.我只是在Linux机器上尝试过,它看起来自动将工作文件夹包含在类路径中,但前提是未设置CLASSPATH环境变量.如果已设置,则应将当前文件夹添加到其中,或在命令行上指定类路径,如下所示:

Make sure you are in the directory that contains the myPack folder. You should not be within the myPack folder. I just tried it on my linux machine and it looks like it automatically included the working folder in the classpath, but only if the CLASSPATH environment variable is NOT set. If it is set, then you should either add the current folder to it, or specify the classpath on the command line as follows:

java -cp . myPack.PasswordVerification

这篇关于运行简单的Java程序时出现NOClassDefFound错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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