Results 1 to 19 of 19

Thread: noClassDefFoundError [SOLVED]

  1. #1

    Thread Starter
    Hyperactive Member gjon's Avatar
    Join Date
    Nov 2004
    Location
    Inescapable Void
    Posts
    442

    noClassDefFoundError [SOLVED]

    I get the following error when trying to run this class file. It seems to compile fine but I just can't get it to run.
    Any help would be appreciated.


    This is what the java source file contains:
    Code:
     
    public class HelloJava {
      public static void main( String[] args ) {
        System.out.println("Hello, Java!");
      }
    }
    Also tried:
    Code:
     
    import javax.swing.*;
      
    public class HelloJava {
      public static void main( String[] args ) {
        JFrame frame = new JFrame( "Hello Java!" );
        JLabel label = new JLabel("Hello Java!", JLabel.CENTER );
        frame.getContentPane(  ).add( label );
        frame.setSize( 300, 300 );
        frame.setVisible( true );
      }
    }
    Last edited by gjon; Dec 10th, 2005 at 01:26 AM.

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: noClassDefFoundError

    try "java HelloJava.class"
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  3. #3

    Thread Starter
    Hyperactive Member gjon's Avatar
    Join Date
    Nov 2004
    Location
    Inescapable Void
    Posts
    442

    Re: noClassDefFoundError

    Don't think I need to add that part unless there is something I am missing from the book I am reading.
    The book states:
    Now that we've got something presentable, let's take a moment to compile and run this example. Place the text in a file called HelloJava.java.

    Now compile this source using the Java compiler, javac:

    % javac HelloJava.java
    This produces the Java bytecode binary class file HelloJava.class.

    You can run the application with the Java virtual machine by specifying the class name (not the filename) as an argument:

    % java HelloJava
    Either way, it is still giving the same error.
    Thanks for making an attempt to solve but it appears to be something else.
    Last edited by gjon; Dec 5th, 2005 at 05:36 PM.

  4. #4

    Thread Starter
    Hyperactive Member gjon's Avatar
    Join Date
    Nov 2004
    Location
    Inescapable Void
    Posts
    442

    Re: noClassDefFoundError

    I tried running this in netbeans and jcreator.
    Both with no luck, but they say that main is missing.
    Not sure how to use those ide's so I'll stick to trying to get it to work in dos.

    Edit: welp, it works in BlueJ just fine. I don't understand why all these things are working and not working the way they are.
    Whats the difference? But my concern is why I can not get it to work via dos. I don't want to use BlueJ.
    Thanks in advance.
    Last edited by gjon; Dec 5th, 2005 at 05:48 PM.

  5. #5
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: noClassDefFoundError

    Are you sure you installed Java 1.4 SE?
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  6. #6

    Thread Starter
    Hyperactive Member gjon's Avatar
    Join Date
    Nov 2004
    Location
    Inescapable Void
    Posts
    442

    Re: noClassDefFoundError

    I think I have installed everything there is to be installed, will the previous post help explain? Would BlueJ work without the SE?

  7. #7
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: noClassDefFoundError

    AS long as it's java, it'll work.
    I don't know what is the problem in your case, but I think re-installing java is a smart move
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  8. #8

    Thread Starter
    Hyperactive Member gjon's Avatar
    Join Date
    Nov 2004
    Location
    Inescapable Void
    Posts
    442

    Re: noClassDefFoundError

    k. i guess i'll have to. Could you do me a favor and provide me with the link to the exact sdk, or jdk or jre I need to dl and install. It can be confusing when you look at javasun's site to figure out exactly what you need. I went with the netbeans complete package. I thought that would include everything.
    Thanks in advance.

    Or maybe I am trying to run it in the wrong directory?
    Here is teh directory I am trying this from in dos.
    E:\Program Files\J2SEE1_4SDK\jdk\bin
    Last edited by gjon; Dec 5th, 2005 at 06:08 PM.

  9. #9
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: noClassDefFoundError

    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  10. #10

    Thread Starter
    Hyperactive Member gjon's Avatar
    Join Date
    Nov 2004
    Location
    Inescapable Void
    Posts
    442

    Re: noClassDefFoundError

    Just to be sure it isn't a directory thing, did you see the edit to the post above?
    I really don't understand the classpath thingy so maybe that has something to do with it.
    O well, its just a stab, thanks for the link. I'll check it out.

    Edit: o ya, i see that program files has a space in that directory> could that be the problem? having installed it to a folder with a space in the name?

  11. #11

    Thread Starter
    Hyperactive Member gjon's Avatar
    Join Date
    Nov 2004
    Location
    Inescapable Void
    Posts
    442

    Re: noClassDefFoundError

    Welp after doing some searching. I found that this is what I needed to type at the command prompt to get it to work properly.
    java -classpath . HelloJava
    Can someone explain what this is actually doing with the classpath?

  12. #12
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Re: noClassDefFoundError

    Perhaps you have a classpath environment variable with no "." as one of the value. Should be .;SomePath;YetAnotherPath;AndSoOn. Try looking at your classpath environment variable.

  13. #13

    Thread Starter
    Hyperactive Member gjon's Avatar
    Join Date
    Nov 2004
    Location
    Inescapable Void
    Posts
    442

    Re: noClassDefFoundError

    Thats the thing, I don't understand classpath at all. How do you go about setting it? Where is it? And what is it for?
    I did some searching on javasuns site but there were mentions of class path in some really advanced programs syntax so I could not gather anything from it.
    Thanks in advance!

  14. #14
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Re: noClassDefFoundError

    It's the way java finds the classes. Classes are compiled by default to become the smallest unit as the .class file. When you go using these classes, java has to find these. That's the path of classes are used for.

    Assuming you have WinXP, go to System Properties. On Advanced Tab, click Environment Variables. Check either User variables or System variables. See if you can find a variable named classpath and check the variable value. Add "." to the variable. Hope this helps.

  15. #15

    Thread Starter
    Hyperactive Member gjon's Avatar
    Join Date
    Nov 2004
    Location
    Inescapable Void
    Posts
    442

    Re: noClassDefFoundError

    E:\Program Files\J2SE\lib\ext\QTJava.zip
    is the current variable for classpath. Should i make it
    E:\Program Files\J2SE\lib\ext\*.*

  16. #16
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Re: noClassDefFoundError

    Make it .;E:\Program Files\J2SE\lib\ext\QTJava.zip

    Give a dot "." for java to find classes on your current directory.

  17. #17

    Thread Starter
    Hyperactive Member gjon's Avatar
    Join Date
    Nov 2004
    Location
    Inescapable Void
    Posts
    442

    Re: noClassDefFoundError

    omg, that worked. I was so like no way, but it did. LOL
    What the heck does .; do?
    Thanks a lot, you helped me get past this huge dilemma as files stopped compiling once I created a seperate class.
    Kudos!

  18. #18
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: noClassDefFoundError

    Search the forum, I think I posted a very long explanation on classpath once.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  19. #19

    Thread Starter
    Hyperactive Member gjon's Avatar
    Join Date
    Nov 2004
    Location
    Inescapable Void
    Posts
    442

    Re: noClassDefFoundError

    I tried a search for class path and found this to be very helpful:

    You need to modify the environment variable PATH.

    Depending on your OS you may be able to do this with AUTOEXEC.BAT. If not, you will need to go into System Properties. I'm not familiar with all the flavors of Windows, but in Win2K, right-click My Computer and select Proberties. Select the Advanced tab and click Environmental Variables. Scroll down the System variables list, select Path and click Edit. In NT (if I remember correctly) you have to go into Environment in the Control Panel

    To make the change to Path, you simply need to add the path to your javac compiler. For example, if you have a basic path variable, it will look something like this:

    C:\WINNT\system32

    All you will need to do is add the location of javac.exe to the list so it looks like this:

    C:\WINNT\system32;c:\jdk1.3\bin

Posting Permissions

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



Click Here to Expand Forum to Full Width