1

I am working along with the ATM Case Study from Deitel java how to program 9th edition.

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.

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:

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.

Note: I am using eclipse, other projects and classes work and run properly.

7
  • Are you sure "come" is correct, in "come.example.atm", etc? Commented Nov 27, 2014 at 10:48
  • What is the package of Atm class ? Commented Nov 27, 2014 at 10:49
  • Make sure that you add the location of your .class file to your classpath. Commented Nov 27, 2014 at 10:50
  • yes it is correct, it was a typing error instead of com but it is just a package name so it can be anything. Atm has the same package as AtmRun Commented Nov 27, 2014 at 10:52
  • see this stackoverflow.com/questions/16334625/… Commented Nov 27, 2014 at 10:57

1 Answer 1

0

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. 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.

Sign up to request clarification or add additional context in comments.

6 Comments

i did try compiling and running it like that, i also tried with -d and -cp. yet it still gives me the AtmRun.java:5: error: cannot find symbol... that i mentioned in the question. i have no idea why its not working everything is just straight forward
Can you share the whole path of Atm.java and AtmRun.java?
No problem. Put the first 10 lines of both java files. Also step your are following to compile and run code with the directories .
the whole class AtmRun is there,Atm has declarations and a constructor that defines the variables. the path is /Users/user/Dropbox/onlineWorkspace/Case study: ATM/src/come/example/atm
and the steps are trivial. either run in ecipse or using javac in the ompiler there is nothing to state
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.