Exception in thread
package javaapplication1;
import java.io.*;
publicclass InputDemo{
/** Creates a new instance of InputDemo */
public String readStr()throws IOException{
InputStreamReader isr =new InputStreamReader(System.in);
BufferedReader br =new BufferedReader(isr);
return br.readLine();
}
publicint readInt()throws IOException, NumberFormatException{
return Integer.parseInt(readStr());
}
publicstaticvoid main(String args[]){
InputDemo ipd =new InputDemo();
String str ="";
int a = 0;
try{
System.out.print("Enter a string :");
str = ipd.readStr();
System.out.print("Enter a number: ");
a = ipd.readInt();
System.out.println("The recently inputted string: " + str);
System.out.println("The recently inputed number: " + a);
}catch(IOException e1){}
catch(NumberFormatException e2){}
}
}
When i complie this above snippet of code, no problem. But when i run it, i got problem as follow:
E:\Java Programmes>javac InputDemo.java // no problem with compiling
E:\Java Programmes>java InputDemo//problem with running
Exception in thread "main" java.lang.NoClassDefFoundError: InputDemo (wrong name
: javaapplication1/InputDemo)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
And i try to find the cause underlying the problem. And when i remove the line "package javaapplication1;" , i could solve the problem. I cannot understand why it is like that. Anyone can explain it to me. Thanks for your teaching.

