• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

getting error while running small program

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Any sufficiently advanced technology will be used as a cat toy. And this tiny ad contains a very small cat:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic