Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-10-2009, 01:11 PM
Member
 
Join Date: Feb 2009
Posts: 2
Rep Power: 0
ziisrick is on a distinguished road
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++):

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:

Code:
javac comparisonDemo.java
but upon entering:

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

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.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 02-10-2009, 01:17 PM
CJSLMAN's Avatar
Moderator
 
Join Date: Oct 2008
Location: Mexico
Posts: 1,159
Rep Power: 3
CJSLMAN is on a distinguished road
Default Running Java programs...
When you run the program, you do it the following way:
Quote:
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.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 02-10-2009, 01:19 PM
Member
 
Join Date: Feb 2009
Posts: 2
Rep Power: 0
ziisrick is on a distinguished road
Default
hahahahaha oh man I need to go to bed. Thanks.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 02-10-2009, 01:23 PM
CJSLMAN's Avatar
Moderator
 
Join Date: Oct 2008
Location: Mexico
Posts: 1,159
Rep Power: 3
CJSLMAN is on a distinguished road
Default No problem...
You're welcome...

Luck,
CJSL
__________________
Chris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 02-10-2009, 01:32 PM
rakesh_n_mehta's Avatar
Member
 
Join Date: Oct 2008
Posts: 62
Rep Power: 0
rakesh_n_mehta is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Could not find the main class, program will exit. aryubi New To Java 39 02-19-2010 11:02 AM
"source not found" at debug time when creating new class rafamd11 New To Java 0 11-22-2008 02:49 AM
failure at Class.forName("oracle.jdbc.driver.OracleDriver"); RonNYC Eclipse 1 03-14-2008 03:51 PM
ERROR: Exception in thread "main" java.lang.NoSuchMethodError: main barney New To Java 1 08-07-2007 08:10 AM
Error: Could Not Find Main Class. Program Will Exit silvia New To Java 1 07-19-2007 05:58 PM


All times are GMT +2. The time now is 07:25 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org