Results 1 to 14 of 14
  1. #1
    JonBrad's Avatar
    JonBrad is offline Member
    Join Date
    Jan 2010
    Posts
    5
    Rep Power
    0

    Question Help with compiling HelloWorldApp

    I was hoping someone could help me. I searched these forums for an answer to this question but couldn't seem to find anything that worked or related to my issue.

    I'm trying to compile the HelloWorldApp from the command prompt but am receiving the following message when I press enter.

    (Quotes mine)

    " Error occurred during initialization of VM
    java/lang/NoClassDefFoundError: java/lang/object "

    :confused:

    From command prompt I've got the cd set to C:\Program Files\Java\jdk6\bin where the javac.exe is located. The HelloWorldApp.java is in the Java folder next to the jdk6 sub folder. The HelloWorldApp also shows when I enter dir for C:\Program Files\Java

    What I have before I press enter is;

    C:\Program Files\Java\jdk6\bin javac HelloWorldApp.java

    That's when I get the error message.

    Fairly certain that this has nothing to do with coding in the HelloWorldApp but here it is just the same.

    XML Code:
    class HelloWorldApp {
        public static void main(String[] args) {
            System.out.println("Hello World!"); // Display the string.
        }
    }

    I'm new to these forums, Java and programming so please be patient with me if the solution to my problem is stupidly simple.


    Thank you,

  2. #2
    [RaIdEn] is offline Senior Member
    Join Date
    Oct 2009
    Location
    California,US
    Posts
    201
    Rep Power
    5

    Default

    try rebooting and try
    if not reinstall jdk. then try .

  3. #3
    [RaIdEn] is offline Senior Member
    Join Date
    Oct 2009
    Location
    California,US
    Posts
    201
    Rep Power
    5

    Default

    Double post

  4. #4
    JonBrad's Avatar
    JonBrad is offline Member
    Join Date
    Jan 2010
    Posts
    5
    Rep Power
    0

    Default

    Thank you for the suggestions [RaIdEn].

    Unfortunately the restart of the computer didn't do it and I'm having problems reinstalling from the Sun website.

    I decided to remove the previous install but I keep getting the message I have an installation already every time I try to download and install the JDK from the Sun website.

    Any ideas where the files could be hiding if they don't show up when you run Search?

  5. #5
    [RaIdEn] is offline Senior Member
    Join Date
    Oct 2009
    Location
    California,US
    Posts
    201
    Rep Power
    5

    Default

    1st try to uninstall JDK
    Start>Settings>Control Panel>add or remove programs.

    if you want further info about the error.
    error

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,526
    Blog Entries
    7
    Rep Power
    20

    Default

    This may be a silly question but nevertheless: you have a 'jdk' directory somewhere after the installation. Not only the 'jdk' is installed but also the 'jre' (Java Runtime System) is installed by the installation process; you should have a 'jre' directory next to your 'jdk' directory. Go to that 'jre' directory; does it contain a subdirectory 'lib' and does that sub directory contain a (large) file 'rt.jar'? That file is essential for the Java Virtual Machine because it contains all the core classes, including the root of all classses: 'Object'. Your installation can't seem to find that class so you might accidentally have installed the JEE packages, not the JSE package.

    kind regards,

    Jos

  7. #7
    gcampton Guest

    Default

    jdk downloads

    If what Jos says is correct then you'll need this link.
    It's the first download on the page, and the documentation (java api) is the 7th on the list.
    for the docs, you can unzip to C:\Program Files\Java\jdk1.6.0_17\docs if you have done a default install.

    Edit: notice that directory is slightly different to the one you had posted earlier.
    Last edited by gcampton; 01-09-2010 at 12:50 PM.

  8. #8
    JonBrad's Avatar
    JonBrad is offline Member
    Join Date
    Jan 2010
    Posts
    5
    Rep Power
    0

    Default

    JosAH, thanks for the suggestion. I followed link provided by [RaIdEn] and read the information there regarding the/a missing rt.jar file and sure enough that was the case.

    I managed, after having to resort to using the MCU, to get a fresh installation of the JDK with the JRE folder containing the the rt.jar file. Ran the javac command and managed to create the .class file for HelloWorldApp.

    Only other issue I had before I successfully ran the HelloWorldApp file was a;

    Exception in thread "main" java.lang.NoClassDefFoundError message.

    I was able to resolve this by using java -cp . HelloWorldApp, so problem solved.

    If anyone would like to offer a way to prevent me having to use -cp . before I mark this thread as resolved I'd appreciate it though.

    Both the .java and .class files were being listed in the cd, which was;

    C:\Program Files\Java\jdk6\bin

    Here's the code I used in the HelloWorldApp.java file if it helps.
    XML Code:
     
    
    /** 
     * The HelloWorldApp class implements an application that
     * simply prints "Hello World!" to standard output.
     */
    class HelloWorldApp {
        public static void main(String[] args) {
            System.out.println("Hello World!"); // Display the string.
        }
    }

    Thanks for all the help though guys!!!:)
    Last edited by JonBrad; 01-09-2010 at 01:06 PM. Reason: removed an extra "managed"

  9. #9
    gcampton Guest

    Default

    yea you can add your java/bin directory in the environment variables on windows:

    * go right click on computer and click properties -> system -> advanced tab -> environment variables
    * on the second text field click on path and then the edit button
    * press the right arrow key so you don't overwrite all the other enivronment variables then add a ";" semi-colon
    * now paste your java path in here at the end, when done it should look something like this:

    Java Code:
    %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\Java\jdk1.6.0_17\bin;
    or something similar

  10. #10
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,526
    Blog Entries
    7
    Rep Power
    20

    Default

    A bit of advice: get your own .java (and .class files) out of those directories; that directory is for the Java (executable) files that come with the distribution. Add the directories where the .exe files are stored to your 'path' variable so they can be found no matter your current working directory (that's a system thingy and has nothing to do with Java).

    About that '-cp .' flag: better get used to it because that's how Java works: you supply the directory listing where the .class files are stored as well as the .jar files; the Java Virtual Machine doesn't guess for them. Of course nothing prevents you from using a shell script or .bat file for those purposes.

    kind regards,

    Jos

  11. #11
    gcampton Guest

    Default

    yea like Jos says, I forgot to mention because I deleted all my other things out of my path to lessen confusion. but you can append a "." at the end of the path as well.

    Java Code:
    %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\Java\jdk1.6.0_17\bin;C:\Qt\2009.05\bin;C:\Cygwin\bin;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;.;

  12. #12
    JonBrad's Avatar
    JonBrad is offline Member
    Join Date
    Jan 2010
    Posts
    5
    Rep Power
    0

    Default

    Quick question gcampton.

    Do I need to restart the computer for the change I make to the Environment Variables take affect?

  13. #13
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,526
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by JonBrad View Post
    Do I need to restart the computer for the change I make to the Environment Variables take affect?
    It doesn't harm but restarting your shell/command line interpreter should be enough.

    kind regards,

    Jos

  14. #14
    JonBrad's Avatar
    JonBrad is offline Member
    Join Date
    Jan 2010
    Posts
    5
    Rep Power
    0

    Default

    Unfortunately neither restarting the command line nor the computer solved the
    Exception in thread "main" java.lang.NoClassDefFoundError message.

    It's not that big of a deal and, as JosAH pointed out, I'll need to get used to the -cp . flag so I've marked the thread as resolved.

    Thanks again for all of your help. I've spent too much time on gaming forums and had forgotten that online forums can actually be helpful rather than just full of spammers and trolls.

Similar Threads

  1. compiling problems.
    By Tikasas in forum New To Java
    Replies: 7
    Last Post: 04-13-2009, 10:00 PM
  2. Having error while compiling
    By Kodeee in forum New To Java
    Replies: 12
    Last Post: 03-17-2009, 11:08 AM
  3. Package Compiling
    By kaperks in forum Advanced Java
    Replies: 1
    Last Post: 02-23-2009, 02:56 PM
  4. Compiling with Different Classes
    By Moncleared in forum Advanced Java
    Replies: 5
    Last Post: 02-03-2009, 06:20 AM
  5. Error while compiling
    By ai_2007 in forum Advanced Java
    Replies: 1
    Last Post: 07-01-2007, 11:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •