[英]Error running java programs
Every program I run in java gives similiar error. 我在Java中运行的每个程序都会产生类似的错误。
This is a helloworld program: 这是一个helloworld程序:
Exception in thread "main" java.lang.NoClassDefFoundError: helloworld (wrong nam
e: helloworldapp)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: helloworld. Program will exit.
The class file helloworld.class
contains a class called helloworldapp.class
. 类文件helloworld.class
包含一个名为helloworldapp.class
的类。 The only real reason for this that I can think of is that you manually renamed the .class
file. 我能想到的唯一真正的原因是您手动重命名了.class
文件。
That won't work! 那行不通! A class called helloworldapp
must be found in a .class
file called helloworldapp.class
. 称为A类helloworldapp
必须在找到.class
文件称为helloworldapp.class
。
If you want to change the name of the class, rename the .java
source file, edit the class
definition and recompile it. 如果要更改类的名称,请重命名.java
源文件,编辑class
定义并重新编译。
How do you start the Java program? 您如何启动Java程序? Are you passing the arguments correctly? 您是否正确传递了论点? Pay attention to the class path. 注意上课的路径。 If you have helloworld.java file and have compiled it to helloworld.class, you should run it like this (from a command prompt in the same directory the class file is located): 如果您拥有helloworld.java文件并将其编译为helloworld.class,则应按以下方式运行它(从与该类文件位于同一目录中的命令提示符):
java -cp . helloworld
Try this one: 试试这个:
public class HelloWorld
{
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}
Read this tutorial about this problem. 阅读有关此问题的本教程 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.