Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

getting error while running small program  RSS feed

 
jojoba saxena
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
error
D:\java>java ParseDemo
Exception in thread "main" java.lang.NoClassDefFoundError: ParseDemo

program
import java.io.*;
class ParseDemo{
public static void main(String args[])throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str;
int i;
int sum;
System.out.println("enetr the numbers, 0 to quit");
do{
str=br.readLine();
try{
i=Integer.parseInt(str);}
catch(NumberFormatException e){
System.out.println("invalid format");
i=0;
}
sum+=i;
System.out.println("Current sumis : "+sum);
}while(i!=0);
}}
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is most likely a problem with the CLASSPATH. Where is the .class file?
 
jojoba saxena
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thnks..i got it..i looked for class file...which some how was missing...i compiled theprogram again....and its has worked now.
there was one error..that sum was not initialized.
 
David Irwin
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would agree...this sounds like a classpath problem. First you need to determine the package you used (defined at the top of your source file, most likely in this case it's in the default package). Then go to the root directory (if you used the default package the compiled file won't be in any subdirectories). Then from the command line you can run your program by typing java <classname with main method>.

If you used something other than the default package, like in the following:



To run the application, from the command line change to the root directory where you compiled the files (you should see the "foo" directory) and then type java foo.bar.Test.

Hope this helps.

Dave
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!