Forum     

Go Back   Digit Technology Discussion Forum > Portables, Peripherals and Electronics > QnA (read only)
Register FAQ Calendar Mark Forums Read

QnA (read only) Mods please help transfer the contents of this forum to proper sections. :)


 
 
LinkBack Thread Tools Search this Thread Display Modes
Old 30-08-2005, 08:17 PM   #1 (permalink)
Alpha Geek
 
g_goyal2000's Avatar
 
Join Date: Jul 2004
Location: New Delhi
Posts: 628
Default Problem in execution of JAVA programs


I have J2SE Development Kit 5.0 as well as J2SE Runtime Environment 5.0 Update 3 installed on my machine running Windows XP SP2. I use MS-DOS for compiling & running Java programs.

I have installed J2SE Development Kit 5.0 in directory D:\jdk1.5.0
& J2SE Runtime Environment 5.0 Update 3 in default installation directory D:\Program Files\Java\jre1.5.0_03

When I compile any Java program using X:\javac <filename.java> command, the file complies properly & all the classes are formed.

But when I run the program using X:\java <classname> command, it gives me an error
"Exception in thread "main" java.lang.NoClassDefFoundError: Gaurav"

Even a simple "Hello World" program isn't running.
Here's the coding for "Hello World".

class Gaurav{
public static void main (String args[]){
System.out.println("Hello World");
}
}

I have set the paths properly.
Here is the path.

SET PATH=D:\jdk1.5.0\BIN;D:\jdk1.5.0\DEMO;D:\jdk1.5.0\ INCLUDE;D:\jdk1.5.0\LIB;D:\jdk1.5.0\JRE;D:\Windows \System32\wbem\;D:\Windows\System32\;
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WS F;.WSH

My institute has JDK 1.3 installed on the machines & the all the Java programs (even Hello World) work fine. I try all the programs at home that I try (and also work fine) at my institute but none work at home PC.

What's the problem?
Kindly help.
__________________
Dell Studio 1558, Intel i5 M430 @ 2.27 Ghz, 4 GB RAM, 1 GB ATI 5470 Mobility, 500 GB HDD, IDT HD Audio with Creative X-Fi MB software
g_goyal2000 is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 30-08-2005, 10:57 PM   #2 (permalink)
Wise Old Owl
 
desertwind's Avatar
 
Join Date: Nov 2004
Location: Hyderabad
Posts: 1,096
Default

And what does this one have to do with Open Source ? Must in QnA. Reporting.

Back to your Q. I 'm no Java expert. well, just a simple note, have you set the filename similar to the Classname ? on the above example, the filename must be Gaurav.java
__________________
Sometime you'll think you understand everything

...Then you'll regain consciousness
desertwind is offline  
Old 31-08-2005, 01:12 PM   #3 (permalink)
In The Zone
 
#/bin/sh's Avatar
 
Join Date: Apr 2004
Location: 42.65 N 73.76 W
Posts: 213
Default

public class HelloWorld {

public static void main (String[] args) {
System.out.println("Hello, world!\n");
}

}


Java of course is case-sensitive, so the class name must be exactly as declared in the class file, and the same as the file name.
__________________
\"99 little bugs in the code, 99 bugs in the code, fix one bug, compile it again, 148 little bugs in the code. 148 little bugs in the code....\"
#/bin/sh is offline  
Old 31-08-2005, 01:59 PM   #4 (permalink)
Jai Suresh
 
lywyre's Avatar
 
Join Date: Aug 2004
Location: Vellore, TN
Posts: 580
Default

what name didu give for the file. It should be "Gaurav.java" in this case.
lywyre is offline  
Old 01-09-2005, 12:48 AM   #5 (permalink)
In The Zone
 
#/bin/sh's Avatar
 
Join Date: Apr 2004
Location: 42.65 N 73.76 W
Posts: 213
Default

i think we missed g_goyal2000.
__________________
\"99 little bugs in the code, 99 bugs in the code, fix one bug, compile it again, 148 little bugs in the code. 148 little bugs in the code....\"
#/bin/sh is offline  
Old 01-09-2005, 11:17 AM   #6 (permalink)
Wise Old Owl
 
Join Date: Jul 2004
Location: Bangalore
Posts: 1,208
Default

two things:

1) Make sure the filename and the class name's are identical including case's.

2) Setting the PATH alone is not enough. You will need to set the CLASSPATH as well. This can be done on the system level or on the Command prompt level. To run the current set of comiled java classes In the command window type the following:

Set CLASSPATH=%CLASSPATH%;.

This will take the existing class path and append the "." to it which is to indicate the current working directory. Now run the java program and it should work.

hope this helps.
__________________
AMD 64 3500+ Venice
DFI Lan Party Ultra-D
2* 512 MB PdP Memory with 2-2-5L timings
XFX 7900GT 256 MB Card
icecoolz is offline  
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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


 
Latest Threads
- by Charan
- by abhidev
- by Sujeet
- by Sarath
- by Krow

Advertisement




All times are GMT +5.5. The time now is 08:55 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2