anxx0018
asked on
a small question about exception
I am new to Java Programming. I am trying to read from a file, but have the runtime error. Can anybody help me with this? Thank you very much!
Here is my code:
import java.lang.*;
import java.io.*;
class FileHandle {
public static void main() throws Exception {
File srcFile = new File("/tmp_mnt/home/anqian /DATFILES/ d19981125. dat");
BufferedReader in = new BufferedReader(new FileReader(srcFile));
String text = in.readLine();
System.out.println(text);
System.out.println(text.le ngth());
in.close();
}
}
It can pass the compilation, but has Exception error in runtime. The error is:
Exception in thread "main" java.lang.NoSuchMethodErro r: main
Thank you very much for your help!
Here is my code:
import java.lang.*;
import java.io.*;
class FileHandle {
public static void main() throws Exception {
File srcFile = new File("/tmp_mnt/home/anqian
BufferedReader in = new BufferedReader(new FileReader(srcFile));
String text = in.readLine();
System.out.println(text);
System.out.println(text.le
in.close();
}
}
It can pass the compilation, but has Exception error in runtime. The error is:
Exception in thread "main" java.lang.NoSuchMethodErro
Thank you very much for your help!
public static void main(String[] args)
ASKER
what does this mean?
ASKER
Why does it need "String[] args"?
main() is not the same as main(String[] args).
they're actually different methods, due to polymorphism.
The entry-point to a class *must* be
public static void main(String[] args)
they're actually different methods, due to polymorphism.
The entry-point to a class *must* be
public static void main(String[] args)
and String[] args is just an array of strings specifying any command line parameters (if any) passed in...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
---The entry-point to a class *must* be
public static void main(String[] args)
Does it mean whenever there is a new defined class, it is always ..... main (String[] args), even there is no input parameters passed to the main function?
Thank you a lot!
public static void main(String[] args)
Does it mean whenever there is a new defined class, it is always ..... main (String[] args), even there is no input parameters passed to the main function?
Thank you a lot!
> Does it mean whenever there is a new defined class, it is always ..... main (String[] args), even there is no input parameters passed to the main function?
yes
yes
ASKER
Excellently clear anwser! Thank you very much!
ASKER
Thank you very much, bobbit31.
your welcome ;)