<legend id='ywoUd'><style id='ywoUd'><dir id='ywoUd'><q id='ywoUd'></q></dir></style></legend><tfoot id='ywoUd'></tfoot>

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

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

        java包不存在且源文件错误

        时间:2023-09-27
        • <bdo id='gr6tF'></bdo><ul id='gr6tF'></ul>
          • <tfoot id='gr6tF'></tfoot>

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

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

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

                  本文介绍了java包不存在且源文件错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  所以我创建了一个名为 util 的文件夹,并在其中放置了四个类以及名为 unit10Assignment 的程序.我创建了一个 package util 并在每个类代码的顶部键入package util;",如下所示:

                  So I made a folder called util and placed four classes along with program named unit10Assignment in it. I created a package util and typed " package util; " at the top of each one of the classes code like this:

                  package util;
                  
                  public class Employee
                  

                  然后我写道:

                  import util.*;
                  import javax.swing.JOptionPane;
                  
                  public class unit10Assignment
                  

                  在程序的顶部.但是,当我编译它时,它会告诉我.有谁知道为什么?我试着玩弄它,当我输入 import java.util*; 时它消失了.相反,但我不确定我的老师想要的作为她的例子没有前面的 java.

                  On top of the program. However when I compile it, it tells me. Anyone know why? I tried playing around with it and it disappeared when I typed in import java.util*; instead but I'm not sure that what my teacher wanted as her example did not have the java in front.

                  它还说错误的源文件"包不包含 Employee 类" 但是,在我输入包语句之前,所有的东西都编译并运行得很好,从那以后我没有对代码进行任何更改.如果我从员工类中删除了包语句,则会出现相同的消息,但它会说另一个类不存在.

                  It also says " bad source file" "package does not contain class Employee " However, everything compiled and ran perfectly before I typed in the package statement and I have not made any change to the code since then. If I removed the package statement from the employee class tho, the same message would appear but it would say another class does not exist.

                  感谢您的帮助注意:不管我放 java.util 还是只放 util,还是会出现这个坏源的问题.

                  Thanks for any help Note: whether or not i put java.util or just util, this problem with the bad source still appears.

                  感谢您的帮助

                  推荐答案

                  我将假设您的项目设置如下:

                  I'm going to make the assumption that you have your project set up like this:

                  util/
                      Employee.java
                      unit10Assignment.java
                  bin/
                  

                  (如果不是,那很好 - 只要它们在 some 文件夹中.但 bin/ 应该存在.)

                  (If it isn't, that's fine - so long as they're in some folder. bin/ should exist, though.)

                  包的工作方式是它们是硬盘驱动器上的文件夹 - 您要导入的包要求您希望导入的文件夹和类都存在于该特定文件夹中.这就是包很方便的原因 - 您可以有两个名为 Employee 的类,并将它们放在完全不同的位置.*

                  The way that packages work is that they're folders on the hard drive - the package you want to import requires that the folder and class you wish to import both exist in that specific folder. This is why packages are handy - you can have two classes named Employee and have them live in completely different locations.*

                  以下是如何在不使用 IDE 的情况下将它们编译成类似包的结构.将 $HOME 替换为 Java 类文件夹的完整路径.

                  Here's how you compile these into a package-like structure without the use of an IDE. Substitute $HOME for the full path of your Java class folder.

                  javac -sourcepath $HOME/util -d $HOME/bin *.java
                  

                  这是你运行主类的方式:

                  And here's how you run your main class:

                  java -cp $HOME/bin util.$MAIN_CLASS
                  

                  这些标志的含义细分:

                  • -sourcepath 指示 javac 在此特定目录中查找您的源文件.
                  • -d 指定 .class 文件的输出目录.
                  • -cp 指示 java 将此文件夹添加到其类路径中.
                  • -sourcepath instructs javac to look in this specific directory for your source files.
                  • -d specifies an output directory for your .class files.
                  • -cp instructs java to add this folder to its classpath.

                  *:非常非常大的项目通常可以使用与其他类相同的名称;如果您想使用特定的类名,则必须为其使用完全限定的类名.支持>

                  这篇关于java包不存在且源文件错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:读取 jar 包中的 xml 文件 下一篇:没有域关联的 java 包名称的约定是什么?

                  相关文章

                  最新文章

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

                    <tfoot id='xbzZ3'></tfoot>

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

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