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.

Hussein Shehady
  • 217
  • 1
  • 2
  • 14

1 Answers1

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.

Abs
  • 100
  • 9
  • 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 – Hussein Shehady Nov 27 '14 at 12:32
  • Can you share the whole path of Atm.java and AtmRun.java? – Abs Nov 27 '14 at 16:20
  • No problem. Put the first 10 lines of both java files. Also step your are following to compile and run code with the directories . – Abs Nov 27 '14 at 20:23
  • 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 – Hussein Shehady Nov 28 '14 at 11:12
  • and the steps are trivial. either run in ecipse or using javac in the ompiler there is nothing to state – Hussein Shehady Nov 28 '14 at 11:13
  • Goto below location using cmd /Users/user/Dropbox/onlineWorkspace/Case study: ATM/src/ And execute this command. javac come\example\atm\AtmRun.java Please show me packages written on first line of both files. – Abs Nov 29 '14 at 07:55