简体   繁体   English

Java编译错误:

[英]Java Compiling Error:

I am working along with the ATM Case Study from Deitel java how to program 9th edition. 我正在与Deitel Java的ATM案例研究一起编写第9版程序。

The case study is at chapter 13, page 546(in case someone has the book and would like to check),I am sure my code is 100% as the book suggested. 案例研究位于第546页的第13章(如果有人拿着本书并想检查),我确定我的代码是本书所建议的100%。

I have all the code set but when I try to run the program it is giving me this: 我已经设置了所有代码,但是当我尝试运行程序时,它就给了我:

Error: Could not find or load main class come.example.atm.AtmRun

when I tried to compile the class by using terminal from the class path it gave me this error: 当我尝试从类路径使用终端编译类时,出现了以下错误:

localhost:atm user$ javac AtmRun.java
AtmRun.java:5: error: cannot find symbol
        Atm theATM = new Atm();
        ^
  symbol:   class Atm
  location: class AtmRun
AtmRun.java:5: error: cannot find symbol
        Atm theATM = new Atm();
                         ^
  symbol:   class Atm
  location: class AtmRun
2 errors

this is the class am running: straight forward but I cant seem to find the problem. 这是课程正在运行:直截了当,但我似乎找不到问题。 any help? 有什么帮助吗?

package come.example.atm;
public class AtmRun {

    public static void main (String[] args){
        Atm theATM = new Atm();
        theATM.run();
    }
}

UPDATE: when i run the .class file from the bin directory of project using command java AtmRun i get this: 更新:当我使用命令java AtmRun从项目的bin目录运行.class文件时,我得到以下信息:

Exception in thread "main" java.lang.NoClassDefFoundError: AtmRun (wrong name: come/example/atm/AtmRun)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)

Class Atm has a constructor Atm() and public void run() along with other methods, the class is big so i think its better if I don't post the code it however you can check in the book if you can. Atm类具有构造函数Atm()和public void run()以及其他方法,该类很大,所以我认为如果我不发布代码会更好,但是如果可以的话,可以在书中检查。

Note: I am using eclipse, other projects and classes work and run properly. 注意:我正在使用eclipse,其他项目和类可以正常运行。

for me it worked. 对我来说,它奏效了。 Please follow below steps: 请按照以下步骤操作:

Y:\HashmiAb\Desktop\Trash\test>javac come\example\atm\Atm.java

Y:\HashmiAb\Desktop\Trash\test>javac come\example\atm\AtmRun.java

Y:\HashmiAb\Desktop\Trash\test>java come.example.atm.AtmRun
Heloo

It matters how you use -d and -cp options of javac and java commands. 如何使用javac和java命令的-d和-cp选项很重要。 I didn't use any of this options. 我没有使用任何这些选项。

For more help please find the directory structure. 要获得更多帮助,请找到目录结构。

+test
-+come
 -+example
  -+atm
   -AtmRun.java
   -Atm.java

Thanks. 谢谢。

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

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