Results 1 to 19 of 19
  1. #1
    gauravmanral's Avatar
    gauravmanral is offline Gaurav Manral
    Join Date
    Jul 2011
    Location
    Delhi
    Posts
    37
    Rep Power
    0

    Question how to set class path in eclipse???

    could not find the main class. Program will exit.

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



    this is the error when i'm compiling my programs.

    plz help.

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

    Default

    Whle *compiling* your program? Eclipse takes care of all classpath settings and issue, that's what a proper ide is supposed to do. Maybe you can elaborate on this a bit?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    fakepics500 is offline Member
    Join Date
    Jul 2011
    Posts
    43
    Rep Power
    0

    Default

    the problem is you saved your program with another class name

    save the program with class that contains your main function
    eg.
    Java Code:
    class my
    {
    }
    class mymain
    {
    public static void main(String ar[])
    {
    }
    }
    save program with mymain.java

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,327
    Rep Power
    25

    Default

    Is that all of the error message?
    Usually the message contains the name of the missing class:
    java.lang.NoClassDefFoundError: THEMISSINGCLASS

  5. #5
    gauravmanral's Avatar
    gauravmanral is offline Gaurav Manral
    Join Date
    Jul 2011
    Location
    Delhi
    Posts
    37
    Rep Power
    0

    Default

    java.lang.NoClassDefFoundError: packagename/classname
    Exception in thread "main"


    this is the complete msg.

  6. #6
    gauravmanral's Avatar
    gauravmanral is offline Gaurav Manral
    Join Date
    Jul 2011
    Location
    Delhi
    Posts
    37
    Rep Power
    0

    Default

    this must not be the problem...
    i hav successfully compiled my programs before with the different names on the same ide.

  7. #7
    gauravmanral's Avatar
    gauravmanral is offline Gaurav Manral
    Join Date
    Jul 2011
    Location
    Delhi
    Posts
    37
    Rep Power
    0

    Default

    my IDE was working correctly but 3 days back i removed the SDK from my system. since then it is unable to compile the program bcz it was unable to find the JRE.
    then i installed SDK again in the system. even then it was unable to compile.

    then somehow i managed to set the path yesterday,( i don't know how) & it started to compile but even was unable to debug.
    BUT 2 hrs back it suddenly start displaying the same error.


    what to do now???

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

    Default

    Eclipse doesn't need a SDK/JDK so it doesn't rely on one. Also, removing a JDK doesn't remove your JRE (on wich your Eclipse does rely). Your description of the symtoms doesn't make much sense; all I can guess is that your Eclipse is posessed, bewitched.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,327
    Rep Power
    25

    Default

    Here is what I get for an error message when there is no .class file:

    Running: D:\Java\jdk1.6.0_25\jre\bin\java.exe -Xmx512M MyPackage.BombGame

    java.lang.NoClassDefFoundError: MyPackage/BombGame
    Where did you get the message you posted in post#5
    Is your class really named: classname
    and your package: packagename?

  10. #10
    gauravmanral's Avatar
    gauravmanral is offline Gaurav Manral
    Join Date
    Jul 2011
    Location
    Delhi
    Posts
    37
    Rep Power
    0

    Default

    when i'm compiling my program a dialog box named "java virtual machine launcher" is generating with error

    could not find the main class. Program will exit.
    and the error in console is

    java.lang.NoClassDefFoundError: ducat/UniqueSet
    Exception in thread "main"


    ducat is package name & UniqueSet is classname

  11. #11
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,327
    Rep Power
    25

    Default

    when i'm compiling my program
    That's strange. That looks like an execution time error.

    Do you know the difference between compiling your program and executing your program?
    Or does the IDE hide all that?

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

    Default

    Quote Originally Posted by Norm View Post
    That's strange. That looks like an execution time error.

    Do you know the difference between compiling your program and executing your program?
    Or does the IDE hide all that?
    Eclipse doesn't hide anything at all, i.e. it shows each and every compilation error in the margins of your source text and it complains when you want to run something that still contains compilation errors; most users don't read those warnings and blindly continue, hoping for the best; they come here afterwards with the most mysterious problems ;-)

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  13. #13
    gauravmanral's Avatar
    gauravmanral is offline Gaurav Manral
    Join Date
    Jul 2011
    Location
    Delhi
    Posts
    37
    Rep Power
    0

    Default

    it's when i'm running my program.

    Quote Originally Posted by Norm View Post
    That's strange. That looks like an execution time error.

    Do you know the difference between compiling your program and executing your program?
    Or does the IDE hide all that?

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

    Default

    Quote Originally Posted by gauravmanral View Post
    it's when i'm running my program.
    Show us the source code of the class you want to run and tell us the name you used for saving that source code.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  15. #15
    gauravmanral's Avatar
    gauravmanral is offline Gaurav Manral
    Join Date
    Jul 2011
    Location
    Delhi
    Posts
    37
    Rep Power
    0

    Default

    package ducat;
    // to check whether this set is unique or not.
    public class UniqueSet {

    public static void main(String s[]) {

    int i,j,x=0,y=0;
    boolean z=false;

    for (i=0;i<s.length;i++)
    {
    x=Integer.parseInt (s[i]);

    for (j=i+1;j<s.length;j++)
    { y=Integer.parseInt (s[j]);

    if (x==y)
    z=true;
    break;

    }
    }

    if (z==false)
    System.out.println ("set is unique.");
    else
    System.out.println ("set is not unique.");

    }

    }


    this is the code.

    not only this my all codes are facing the same problem. even i have executed them successfully before. but now i'm unable to do the same.

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

    Default

    Quote Originally Posted by gauravmanral View Post
    not only this my all codes are facing the same problem. even i have executed them successfully before. but now i'm unable to do the same.
    Did you try to run your class as ducat.UniqueSet? i.e. including the package name.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  17. #17
    gauravmanral's Avatar
    gauravmanral is offline Gaurav Manral
    Join Date
    Jul 2011
    Location
    Delhi
    Posts
    37
    Rep Power
    0

    Default

    yes.
    in eclipse it is always used automatically i think.

  18. #18
    gauravmanral's Avatar
    gauravmanral is offline Gaurav Manral
    Join Date
    Jul 2011
    Location
    Delhi
    Posts
    37
    Rep Power
    0

    Default

    plz tell me how to set class path in eclipse...?

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

    Default

    Quote Originally Posted by gauravmanral View Post
    plz tell me how to set class path in eclipse...?
    You can set a classpath in Eclipse as follows: go to Run > Run Configuration ... select a configuration and select its classpath tab; but I wonder why you should need it because it is all set by Eclipse for you. Especially nothing needs to be done when you want to run an ordinary Java application.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. setting class-path & Library Path in ubantu
    By programmer_007 in forum Eclipse
    Replies: 18
    Last Post: 02-22-2010, 12:31 PM
  2. Read eclipse installation path in java
    By java_kick in forum Advanced Java
    Replies: 0
    Last Post: 03-23-2009, 02:49 PM
  3. Eclipse 3.4 GetProject path
    By Kamil.Khoury in forum Eclipse
    Replies: 0
    Last Post: 01-28-2009, 03:39 PM
  4. Setting up class path for Eclipse
    By tsantana in forum Eclipse
    Replies: 1
    Last Post: 04-07-2008, 07:05 PM

Posting Permissions

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