ClassNotFound编译多个对象类时出错

时间:2011-11-29 21:47:00

标签: java class object compiler-construction

我有一个Store类,它是Person的数组;我有一个人,日期,学生,本科和研究生课程。一切都在Eclipse中运行,我必须从命令行运行它。我已经复制了src文件并试图运行主程序,但它只是说它找不到我的任何类。它们都在同一文件夹中,并且在我分配包的每个类中。我查找了导入类,我尝试了:

    import oopinterface.Person;

等所有课程。

有没有什么方法可以编译主程序,所以它会识别非常清楚的类文件!?我在Windows上,但如果我可以使用Linux的“其他”方式,它会有所帮助吗?

这是编译器错误:

   C:\Users\Liloka\Source\oopinterface>javac ContainerInterface.java
   ContainerInterface.java:41: cannot find symbol
   symbol  : class Store
   location: class oopinterface.ContainerInterface
            Store myList = new Store();

   //Instance of Store
                    ^
   ContainerInterface.java:688: cannot find symbol
   symbol  : class Person
   location: class oopinterface.ContainerInterface
            public Person getSupervisor()
                   ^

..它继续选择其他类中的每个方法..(39) 先感谢您!

3 个答案:

答案 0 :(得分:2)

您的课程似乎在oopinterface包中。从包的基目录编译源文件,如下所示:

C:\Users\Liloka\Source> javac oopinterface\ContainerInterface.java

如果设置了CLASSPATH环境变量,请确保未设置它,或者将可以找到已编译类文件的程序包的基目录添加到类路径中。您还可以使用-cp-classpath选项告诉javac在何处查找已编译的类文件。

您的所有源文件都在文件顶部有package oopinterface;吗?

编译后,从命令行运行程序,执行以下操作:

java -cp C:\Users\Liloka\Source oopinterface.MainClass

其中MainClass是包含public static void main(String[] args)方法的类。 (这假设您编译的类文件与源位于同一目录中。)

答案 1 :(得分:1)

你应该一次编译所有的类,因为它们都引用自己。 cd到Source目录,然后运行

javac oopinterface\*.java

答案 2 :(得分:1)

您需要将类路径设置为指向您的类所在的目录,以便编译器和解释器命令可以找到它。 它看起来像:javac -classpath C:\ Users \ Liloka \ Source \ oopinterface ContainerInterface.java

相关问题