Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

reading integers

  Asked By: Cameron    Date: Dec 10    Category: Java    Views: 879

i have a code

import java.io.*;

class abc

public static void main()
getNextInteger() ;

static int getNextInteger()

String line;

DataInputStream in = new DataInputStream(System.in);
try {
line = in.readLine();
int i = Integer.valueOf(line).intValue();
return i;
catch (Exception e)

return -1;

} // getNextInteger ends here


i am learning java from a tutorial site..this code is compiling but
at the runtime i am getting " Exception in thread "main"
java.lang.NoSuchMethodError: main "

question 1: why " Exception in thread "main"
java.lang.NoSuchMethodError: main "....this error is coming...how
can i remove this?


i could not understand... " int i = Integer.valueOf(line).intValue
();" also. what is going on here????? two methods are here. what is
the job of two method??



4 Answers Found

Answer #1    Answered By: Alexander Fields     Answered On: Dec 10

smitel2003 wrote:

> public static  void main()
> {
> getNextInteger() ;
> }

It is 2:30 am here and I am realy sleepy but shouldn't that be ...

public static void  main (String[] args){...} ?

Answer #2    Answered By: Vivian Ruiz     Answered On: Dec 10

> public static  void main  (String[] args){...}

yes it doesnt compile without it.

i think the AP made a typo

Answer #3    Answered By: Harold Graham     Answered On: Dec 10

even i am a beginer like you... replace main( ) with main(String s[ ] )...it
will work....

can anybody explain me why do we need to have such a syntax..?

Answer #4    Answered By: Giovanna Silva     Answered On: Dec 10

Java assumes that your program is going to accept some sort of argument,
or even that a lack of arguments is a argument.

Didn't find what you were looking for? Find more on reading integers Or get search suggestion and latest updates.