Results 1 to 7 of 7
  1. #1
    ziisrick is offline Member
    Join Date
    Feb 2009
    Posts
    2
    Rep Power
    0

    Exclamation "Could not find the main class: comparisonDemo.class. Program will exit."

    Hello,

    I have been learning java recently on Ubuntu and my MacBook, which has been working completely fine, but I have run into some problems now that I have started doing some on Windows Vista as well.

    My JDK version is 1.6.0_12 and I although I had a previous version of the JRE installed when I came across this problem, I have since removed the older JRE and the problem persists.

    Here is the full .java file that I am trying to run (written with Notepad++):

    Java Code:
    class comparisonDemo {
    	public static void main(String[] args) {
    		int value1 = 1;
    		int value2 = 2;
    		if(value1 == value2) System.out.println("value1 == value2");
    		if(value1 != value2) System.out.println("value1 != value2");
    		if(value1 > value2) System.out.println("value1 > value2");
    		if(value1 < value2) System.out.println("value1 < value2");
    		if(value1 <= value2) System.out.println("value1 <= value2");
    	}
    }
    This is just one of the basic examples from Sun's java tutorial.

    I am compiling this using the command line interface only, as I have been doing on my Mac and Ubuntu. The file (comparisonDemo.java) compiles fine when I enter:

    Java Code:
    javac comparisonDemo.java
    but upon entering:

    Java Code:
    java comparisonDemo.class
    I am presented with the following error:

    Java Code:
    Exception in thread "main" java.lang.NoClassDefFoundError: comparisonDemo\class
    Caused by: java.lang.ClassNotFoundException: comparisonDemo.class
    	at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    	at java.security.AccessControler.doPrivileged(Native Method)
    	at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
    	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
    Could not find the main class: comparisonDemo.class. Program will exit.
    After a good hour with Google I haven't been able to find anything that solves the problem. Can anyone with a little more experience think of anything? Of course, things are still working fine on the other two computers so this isn't going to hurt me too much, but I'd really like to figure out what's going on here.

    I appreciate the help. :)

  2. #2
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default Running Java programs...

    When you run the program, you do it the following way:
    java comparisonDemo
    You don't include the ".class" extention

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  3. #3
    ziisrick is offline Member
    Join Date
    Feb 2009
    Posts
    2
    Rep Power
    0

    Default

    hahahahaha oh man I need to go to bed. Thanks.

  4. #4
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default No problem...

    You're welcome...

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  5. #5
    Join Date
    Oct 2008
    Posts
    73
    Rep Power
    0

    Default

    for running java program,file name with .class extension is not necessary.But u must go to directory in which .class file stored.

    eg.
    if u store ur .java file in c: drive then in command prompt u first go to c: drive like
    c:>javac camparisonDemo.java
    and then press enter.

    for run
    c:>java camparisonDemo

    ur progarm will run succesfully.

    if still not running then
    u add . value in classpath variable.
    Right Click on Mycomputer --> then
    select advanced tab--> then
    click environment variables--> then
    one window is displayed. on that u find classpath variable and append . with comma or if not then add new variable with name classpath and value= . (dot)
    Rakesh Mehta

  6. #6
    pete051 is offline Member
    Join Date
    May 2010
    Posts
    5
    Rep Power
    0

    Default

    I had the same problem as the OP on Debian lenny but it compiled and run perfectly on Fedora 12, and I had remembered that the class extension is not used.
    Java Code:
     import java.util.*;
    public class FindDupes2 {
    public static void main(String [] args) {
    Set<String> s = new HashSet<String>();
    for(String a : args)
    if(!s.add(a))
    System.out.println("dupe"+a);
    System.out.println(s.size() +"words"+s);
    }
    }

  7. #7
    pete051 is offline Member
    Join Date
    May 2010
    Posts
    5
    Rep Power
    0

Similar Threads

  1. Replies: 2
    Last Post: 09-22-2011, 10:48 PM
  2. Could not find the main class, program will exit.
    By aryubi in forum New To Java
    Replies: 39
    Last Post: 02-19-2010, 11:02 AM
  3. Replies: 0
    Last Post: 11-22-2008, 02:49 AM
  4. Replies: 1
    Last Post: 03-14-2008, 03:51 PM
  5. Replies: 1
    Last Post: 08-07-2007, 08:10 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
  •