Page 2 of 2 First 12
  • Jump to page:
    #16
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    18
    Rep Power
    0
    Originally Posted by bullet
    cd means change directory.

    You should now be able to compile and execute the program with

    Code:
    javac helloworld.java
    and

    Code:
    java helloworld

    Code:
    patricias-MacBook-Pro:~ patriciabetzschiff$ cd Desktop
    patricias-MacBook-Pro:Desktop patriciabetzschiff$ ls -l *.java
    -rw-r--r--@ 1 patriciabetzschiff  staff  253 May  5 12:33 helloworld.java
    patricias-MacBook-Pro:Desktop patriciabetzschiff$ javac helloworld.java
    patricias-MacBook-Pro:Desktop patriciabetzschiff$ java helloworld
    Exception in thread "main" java.lang.NoClassDefFoundError: helloworld (wrong name: helloworld/helloworld)
    	at java.lang.ClassLoader.defineClass1(Native Method)
    	at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
    	at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
    	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
    	at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
    	at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
    	at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    This is what i get. I believe that i successfully changed the directory to the Desktop (thank you) and the next command ls -l *.java seemed to work and it looks like the compiling even worked (correct me if im wrong). But it looks like the running is the only thing that didnt work and it seems to be because no class definition was found. This is what it looks like to me.

    And extra question: because i changed the directory to desktop, how could i find out what the directory was set to beforehand. and is it permanently changed, my guess would be no.

    Thanks.
  2. #17
  3. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,021
    Rep Power
    1285
    It appears you have a package statement in the file. Try removing it.
  4. #18
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    18
    Rep Power
    0
    Originally Posted by bullet
    It appears you have a package statement in the file. Try removing it.
    http://i539.photobucket.com/albums/f...loworldyes.png

    Funny, i dont remember using a package statement but it works now. which is the good thing. Just wondering, what would be the way to find out what the directory was originally set to?

    And say i wanted to make myself a little more organized and save my hello world file into a file named "hello world" inside a folder named "programs" that would be on the desktop, how would i change my directory to that folder?

    would i start out with something like
    Code:
    cd Desktop/Programs/helloworld
    because i tried this exact code and it will not find the file. what would i change the directory to in this scenario?


    Thanks
  6. #19
  7. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,021
    Rep Power
    1285
    You would need to make sure that the Programs directory existed on the desktop, and inside of that there is a directory called helloworld.

    Remember that the names of the directories are case-sensitive.
  8. #20
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    18
    Rep Power
    0
    Originally Posted by bullet
    You would need to make sure that the Programs directory existed on the desktop, and inside of that there is a directory called helloworld.

    Remember that the names of the directories are case-sensitive.
    ok, so what would be my steps to making these folders i created, directories?
  10. #21
  11. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,021
    Rep Power
    1285
    Originally Posted by Logan Betz
    ok, so what would be my steps to making these folders i created, directories?
    When you start the terminal, you would change to the desktop.

    Code:
    cd Desktop
    Then create the Programs directory.

    Code:
    mkdir Programs
    Then change into it.

    Code:
    cd Programs
    Then create the helloworld directory.

    Code:
    mkdir helloworld
    Then change into it.

    Code:
    cd helloworld
    With javac you should be in the same directory as the source file.

    With java, the .class file can be in a directory in the CLASSPATH.
  12. #22
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    18
    Rep Power
    0
    Originally Posted by bullet
    When you start the terminal, you would change to the desktop.

    Code:
    cd Desktop
    Then create the Programs directory.

    Code:
    mkdir Programs
    Then change into it.

    Code:
    cd Programs
    Then create the helloworld directory.

    Code:
    mkdir helloworld
    Then change into it.

    Code:
    cd helloworld
    With javac you should be in the same directory as the source file.

    With java, the .class file can be in a directory in the CLASSPATH.
    Every line worked until i tried to compile. No .class file was created. There was no hellworld.java file found.

    Every directory i made is a name of a folder.
  14. #23
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    18
    Rep Power
    0
    Originally Posted by Logan Betz
    Every line worked until i tried to compile. No .class file was created. There was no hellworld.java file found.

    Every directory i made is a name of a folder.
    Nevermind, i tried again and there was a .class file created in that folder. Although, the program won't run. What is it that i have to do about the CLASSPATH?
  16. #24
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    18
    Rep Power
    0
    Originally Posted by Logan Betz
    Nevermind, i tried again and there was a .class file created in that folder. Although, the program won't run. What is it that i have to do about the CLASSPATH?
    NEVERMIND! I tried it again just by repeating the steps and it worked! I just have no idea why a second attempt would be any different than the first? Is there an answer to this?
  18. #25
  19. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,021
    Rep Power
    1285
    Originally Posted by Logan Betz
    NEVERMIND! I tried it again just by repeating the steps and it worked! I just have no idea why a second attempt would be any different than the first? Is there an answer to this?
    When you say second attempt, do you mean you ran javac twice?
  20. #26
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    18
    Rep Power
    0
    Originally Posted by bullet
    When you say second attempt, do you mean you ran javac twice?
    Yes but not consecutively. I changed the directory around several times.
  22. #27
  23. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,021
    Rep Power
    1285
    Originally Posted by Logan Betz
    Yes but not consecutively. I changed the directory around several times.
    The typical procedure is you run javac. This compiles the code to a .class file. After the .class file is generated, you use java to run it.
  24. #28
  25. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    18
    Rep Power
    0
    Originally Posted by bullet
    The typical procedure is you run javac. This compiles the code to a .class file. After the .class file is generated, you use java to run it.
    Thank you so much for the help!
Page 2 of 2 First 12
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo