• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

Running a Java Program

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I am studying for my Java certification exams & am trying to write these 1 line programs & compile & run them, Before I never had any problems running them, but, now after I compile them they dont just run & give me an error as follows:
Exception in thread "main" NoClassDefFoundError:Check2
Where Check2 is the name of my file
my jdk1.2.2 is in c:\ and my bin is in jdk1.2.2 & my java & javac application are in the bin directory
so
c:\jdk1.2.2\bin\java & c:\jdk1.2.2\bin\javac exists
& c:\Neha\Check2 exists
c:\set PATH=%PATH%;c:\jdk1.2.2\bin is the path set
Up until now that is how I Have been running my programs but now I get these errors. It is very irritating to know that now since u have to study for your exams I have to face these errors.
Please help me out with my errors........
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Check out if you have saved the given file as Check2.java and not just Check2 .The error you have named usually arises when u have gone wrong with the naming conventions of the file wherein you place your program.
Hope this helps.
Aparanji.
 
Chamya Pehalvan
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI Aparanji,
I already have my file saved as Check2.java, yet I get this error for all my earlier files as well which I had written a year back!
Please somebody help!

Originally posted by Aparanji Raju:
Hi,
Check out if you have saved the given file as Check2.java and not just Check2 .The error you have named usually arises when u have gone wrong with the naming conventions of the file wherein you place your program.
Hope this helps.
Aparanji.


 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Run the program like this
> java -cp C:\Neha Check2
or you could set up the class path like this
> set classpath=C:\Neha
> java Check2
If it does not work, please post your code here.
[This message has been edited by vasansrini (edited July 30, 2000).]
 
Chamya Pehalvan
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi vasansrini,
I tried to set the path also running it the way you suggested and it still does not work!!! The code is as follows:
package Neha;
public class Check2
{
public static void main(String args[])
{
System.out.println("WELCOME");
}//main method......
}//class Check2

Originally posted by vasansrini:
Run the program like this
> java -cp C:\Neha Check2
or you could set up the class path like this
> set classpath=C:\Neha
> java Check2
If it does not work, please post your code here.
[This message has been edited by vasansrini (edited July 30, 2000).]


 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error is due to the package statement.
Suggestions:
-----------
1. cd \
2. c:\>set classpath=c:\
3. c:\>java Neha.Check2
My last suggestion would be, spend some time on reading how to pacakage your classes.
If you got time, please post it here.
- Srini.

[This message has been edited by vasansrini (edited July 30, 2000).]
 
Chamya Pehalvan
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand what you are trying to say but read the foll.
say you have a file called "check.java" in a package "Java2"
you have your Java2 directory in C:drive directly -ie -
C:\Java2
Now if you set your classpath to c:\Java2 and compile your program:
javac check.java
after setting your path to the bin directory then this should cause no problems as it had caused me no errors before for the pst 6 months. What I am trying to do is the same as what you have said - just that you are setting your classpath just upto C: drive and compiling your program from your parent directory - ie - from Java2.
Thanks for your help though Srini

Originally posted by vasansrini:
The error is due to the package statement.
Suggestions:
-----------
1. cd \
2. c:\>set classpath=c:\
3. c:\>java Neha.Check2
My last suggestion would be, spend some time on reading how to pacakage your classes.
If you got time, please post it here.
- Srini.

[This message has been edited by vasansrini (edited July 30, 2000).]


 
Aparanji Raju
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again,
I dont know much about the language which is there in the batch files.
But right now all i can suggest is doing some correction in your autoexec.bat file.
1.Go to C:\ and open your autoexec.bat file and check out the path.
2My autoexec.bat file has something like this
set path =c:\windows;c:\windows\command;c:\jdk1.2.1;c:\jdk1.2.1\bin (dont put a semicolon here unless u have anymore other software to run which do need the path again.)
This is working fine for me no matter from which directory I run the java files.
If your java version is 1.2.2 make the correction in the path.
3.save,close the file and run the autoexec.bat from C prompt. Just write autoexec.bat at C:\ and press enter key ....It will run the batch file
4.Try compiling your program.
Hope this helps....at least.
bye
Regards,
Aparanji
 
It is sorta covered in the JavaRanch Style Guide.
    Bookmark Topic Watch Topic
  • New Topic