Results 1 to 7 of 7
- 02-10-2009, 12:11 PM #1
Member
- Join Date
- Feb 2009
- Posts
- 2
- Rep Power
- 0
"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++):
This is just one of the basic examples from Sun's java tutorial.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"); } }
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:
but upon entering:Java Code:javac comparisonDemo.java
I am presented with the following error:Java Code:java comparisonDemo.class
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.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.
I appreciate the help. :)
- 02-10-2009, 12:17 PM #2
Running Java programs...
When you run the program, you do it the following way:
You don't include the ".class" extentionjava comparisonDemo
Luck,
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 02-10-2009, 12:19 PM #3
Member
- Join Date
- Feb 2009
- Posts
- 2
- Rep Power
- 0
hahahahaha oh man I need to go to bed. Thanks.
- 02-10-2009, 12:23 PM #4
No problem...
You're welcome...
Luck,
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 02-10-2009, 12:32 PM #5
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
- 05-18-2010, 12:13 PM #6
Member
- Join Date
- May 2010
- Posts
- 5
- Rep Power
- 0
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); } }
- 05-18-2010, 05:11 PM #7
Member
- Join Date
- May 2010
- Posts
- 5
- Rep Power
- 0
Similar Threads
-
Error: Could Not Find Main Class. Program Will Exit
By silvia in forum New To JavaReplies: 2Last Post: 09-22-2011, 09:48 PM -
Could not find the main class, program will exit.
By aryubi in forum New To JavaReplies: 39Last Post: 02-19-2010, 10:02 AM -
"source not found" at debug time when creating new class
By rafamd11 in forum New To JavaReplies: 0Last Post: 11-22-2008, 01:49 AM -
failure at Class.forName("oracle.jdbc.driver.OracleDriver");
By RonNYC in forum EclipseReplies: 1Last Post: 03-14-2008, 02:51 PM -
ERROR: Exception in thread "main" java.lang.NoSuchMethodError: main
By barney in forum New To JavaReplies: 1Last Post: 08-07-2007, 07:10 AM


LinkBack URL
About LinkBacks

Bookmarks