线程'main'中的异常java.lang.NoClassDefFoundError: [英] exception in thread 'main' java.lang.NoClassDefFoundError:

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

问题描述

以下程序抛出错误:

public class HelloWorld {
    public static void main(String args[]) {
        System.out.println("Hello World!"); 
    }
}

CLASSPATH C:\Program Files\Java\jdk1.6.0_18\bin\

Path C:\Program Files\Java\jdk1.6.0_18\bin\

JAVAHOME C:\Program Files\Java\jdk1.6.0_18\bin

请告诉我根本原因?

推荐答案

我发现了另一个常见的原因。如果使用像eclipse这样的IDE在包内创建java文件,您将在java文件的顶部找到包名称,如package pkgName。如果您尝试从命令提示符运行此文件,您将收到NoClassDefFoundError错误。从java文件中删除软件包名称,然后使用命令提示符中的命令。为此浪费了3个小时。 - Abhi

I found one another common reason. If you create the java file inside a package using IDE like eclipse, you will find the package name on the top of your java file like "package pkgName". If you try to run this file from command prompt, you will get the NoClassDefFoundError error. Remove the package name from the java file and use the commands in the command prompt. Wasted 3 hours for this. -- Abhi

在我的情况下,包名是用小写字母写的,虽然包名是大写的。阿比,非常感谢。

In my case, package name was written in small letters though the package name was in capital. Ab Thanks a lot.

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

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