<legend id='xUQ4N'><style id='xUQ4N'><dir id='xUQ4N'><q id='xUQ4N'></q></dir></style></legend>

    1. <small id='xUQ4N'></small><noframes id='xUQ4N'>

      • <bdo id='xUQ4N'></bdo><ul id='xUQ4N'></ul>
    2. <i id='xUQ4N'><tr id='xUQ4N'><dt id='xUQ4N'><q id='xUQ4N'><span id='xUQ4N'><b id='xUQ4N'><form id='xUQ4N'><ins id='xUQ4N'></ins><ul id='xUQ4N'></ul><sub id='xUQ4N'></sub></form><legend id='xUQ4N'></legend><bdo id='xUQ4N'><pre id='xUQ4N'><center id='xUQ4N'></center></pre></bdo></b><th id='xUQ4N'></th></span></q></dt></tr></i><div id='xUQ4N'><tfoot id='xUQ4N'></tfoot><dl id='xUQ4N'><fieldset id='xUQ4N'></fieldset></dl></div>

      <tfoot id='xUQ4N'></tfoot>

        如果 java Hello World 程序在包中,为什么我不能运

        时间:2023-09-27
      1. <legend id='tzjDu'><style id='tzjDu'><dir id='tzjDu'><q id='tzjDu'></q></dir></style></legend>
          <tbody id='tzjDu'></tbody>

          <small id='tzjDu'></small><noframes id='tzjDu'>

          <tfoot id='tzjDu'></tfoot>
            <bdo id='tzjDu'></bdo><ul id='tzjDu'></ul>

                  <i id='tzjDu'><tr id='tzjDu'><dt id='tzjDu'><q id='tzjDu'><span id='tzjDu'><b id='tzjDu'><form id='tzjDu'><ins id='tzjDu'></ins><ul id='tzjDu'></ul><sub id='tzjDu'></sub></form><legend id='tzjDu'></legend><bdo id='tzjDu'><pre id='tzjDu'><center id='tzjDu'></center></pre></bdo></b><th id='tzjDu'></th></span></q></dt></tr></i><div id='tzjDu'><tfoot id='tzjDu'></tfoot><dl id='tzjDu'><fieldset id='tzjDu'></fieldset></dl></div>
                1. 本文介绍了如果 java Hello World 程序在包中,为什么我不能运行它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我创建了一个名为Hello.java"的文件,如下所示:

                  I created a file called "Hello.java" that looks like this:

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

                  我运行 javac Hello.java,然后运行 ​​java Hello,一切都按预期运行.

                  I ran javac Hello.java, then java Hello, and everything worked as expected.

                  然后我将package testpackage;这一行添加到文件的顶部,并将其放在目录/home/matthew/Desktop/hellotest/testpackage中.我将 .:/home/matthew/Desktop/hellotest 放在我的 CLASSPATH 中,并以与以前相同的方式编译和运行.但是现在,我得到了这个错误:

                  I then added the line package testpackage; to the top of the file, and put it in the directory /home/matthew/Desktop/hellotest/testpackage. I put .:/home/matthew/Desktop/hellotest in my CLASSPATH, and compiled and ran the same way as before. But now, I get this error:

                  matthew@matthew-laptop:~/Desktop/hellotest/testpackage$ java Hello 
                  Exception in thread "main" java.lang.NoClassDefFoundError: Hello (wrong name: testpackage/Hello)
                      at java.lang.ClassLoader.defineClass1(Native Method)
                      at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
                      at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
                      at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
                      at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
                      at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
                      at java.security.AccessController.doPrivileged(Native Method)
                      at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
                      at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
                      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
                      at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
                      at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:334)
                  Could not find the main class: Hello. Program will exit.
                  

                  为什么它可以单独工作,而不是在一个包中?

                  Why did it work on its own, but not in a package?

                  推荐答案

                  既然在testpackage里面,它的名字真的是testpackage.Hello.所以去一个目录并在上面执行 java.

                  Now that it's in testpackage, its name is really testpackage.Hello. So go up a directory and do java on that.

                  这篇关于如果 java Hello World 程序在包中,为什么我不能运行它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:无法导入类,IntelliJ 显示 BOOT-INF 前缀,似乎相关 下一篇:为什么 Android Studio 遇到大写包名的问题?

                  相关文章

                  最新文章

                  <i id='DMPrP'><tr id='DMPrP'><dt id='DMPrP'><q id='DMPrP'><span id='DMPrP'><b id='DMPrP'><form id='DMPrP'><ins id='DMPrP'></ins><ul id='DMPrP'></ul><sub id='DMPrP'></sub></form><legend id='DMPrP'></legend><bdo id='DMPrP'><pre id='DMPrP'><center id='DMPrP'></center></pre></bdo></b><th id='DMPrP'></th></span></q></dt></tr></i><div id='DMPrP'><tfoot id='DMPrP'></tfoot><dl id='DMPrP'><fieldset id='DMPrP'></fieldset></dl></div>
                2. <legend id='DMPrP'><style id='DMPrP'><dir id='DMPrP'><q id='DMPrP'></q></dir></style></legend>
                      <tfoot id='DMPrP'></tfoot>

                    1. <small id='DMPrP'></small><noframes id='DMPrP'>

                        <bdo id='DMPrP'></bdo><ul id='DMPrP'></ul>