java - eclipse acting weird when creating methods -
i don't see wrong here, working on different method had problems tried simplify check mistake ended going simple method , still have same error.
when put mouse on redx @ line 6 message saying:
multiple markers @ line -syntax error on token "(",;expected -syntax error on token ")",;expected`
mouse @ line 7 says:
void method cannot return value 2 quick fixes available change method return type 'int' change 'return;'
i changed public static void public static int , changed method's modifier error @ line 6 appears everytime. don't see wrong here think i'm making mistake needs simple fix, going crazy? never had particular problem before
the problem declaring method called y
within main
method. in java, cannot nest method declerations.
you have move outside main
method scope or else, declare private inner class hold y
method.
in short:
public class gat { public static void main(string args[]) { ... } int y(int a) { return + 5; } }
or:
public class gat { public static void main(string args[]) { class inner { int y (int a) { return + 5; } } } }
the first approach common, end using second approach, when dealing swing events , other threading aspects.
Comments
Post a Comment