简体   繁体   English

无法运行Java程序

[英]Unable to run Java program

I'm having trouble running my very first piece of java. 我在运行我的第一部分Java时遇到了麻烦。 I was able to compile it and produce a .class file, but then I was unable to run it for some reason. 我能够编译它并生成一个.class文件,但是由于某种原因,我无法运行它。 It might have something to do with the directory path. 它可能与目录路径有关。 The file name is "Simple" and I have this saved in a folder called "newfolder". 文件名为“ Simple”,我将其保存在名为“ newfolder”的文件夹中。

I was able to compile Simple.class by typing in "javac newfolder/Simple.java", but when I typed in "java newfolder/Simple", this message appeared: 通过键入“ javac newfolder / Simple.java”,我能够编译Simple.class,但是当我键入“ java newfolder / Simple”时,此消息出现了:

java: exception in thread “main” java.lang.NoClassDefFoundError: newfolder/Simple (wrong name: Simple)

Here is the original code that I typed in: 这是我输入的原始代码:

// This is a simple Java program.

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

I think that the answer here is up my alley, but I've somehow been unable to get it to work for me, so any assistance would be greatly appreciated. 我认为这里的答案就在我的小巷,但我一直无法以某种方式为我工作,因此,我们将不胜感激。 Thanks in advance! 提前致谢!

Try running the Java file from inside the newfolder/ 尝试从newfolder /内部运行Java文件

cd newfolder/
java Simple

I suspect you want to use an IDE which sets up these things for you but you need 我怀疑您想使用一个IDE为您设置这些东西,但是您需要

package newfolder;

at the start. 在开始时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM