• 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
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

getting error while running small program

 
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);
}}
 
Ranch Hand
Posts: 2410
  • 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.
 
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
 
Heroic work plunger man. Please allow me to introduce you to this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic