This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
Now this is just weird. I've got a class, networkConnect, which contains a method, prepContFoo(). From my main, controlling class's main portion, I've instantiated a networkConnect object and then attempted to call its prepContFoo() method, thusly: networkConnect nc = new networkConnect(); nc.prepContFoo(); That should, in a pretty straightforward manner, call that function. Instead, my compiler tells me: runGnutonic.java:17: Invalid method declaration; method name required. nc.prepContFoo(); ^ Here is how prepContFoo() is defined: public class networkConnect { ... public prepContFoo() { String payload = null; for (int x=0;x<=10;x++) { payload += java.lang.Math.Random().toString(); } System.out.println(payload); } ... } What could I possibly be doing wrong? Alex Kirk
kyle amburn
Ranch Hand
Joined: Jul 29, 2001
Posts: 64
posted
0
Hi- In the above code you do not have a return type declared for the method prepContFoo(). You need void or a return type. Kyle
Alex Kirk
Ranch Hand
Joined: Aug 13, 2001
Posts: 44
posted
0
That's true, but even when I fixed that, my error persists. Any other thoughts? Alex
With JDK1.3, the error is different and less helpful (but i'm more used to it, so it took me some time to duplicate the error). But with 1.1.8 and 1.2.2 you get: "Method name required" Which means that you are trying to call an object's method, when the compiler feels that you should be declaring a new method. Which is what you're supposed to be doing if you type outside of a block. In other words, the problem is not in the method declaration, it's in where you are calling it. [This message has been edited by Mike Curwen (edited August 16, 2001).]
Alex Kirk
Ranch Hand
Joined: Aug 13, 2001
Posts: 44
posted
0
::Very chagrined:: Yup, you were right. I'd accidentally placed it outside of the closing brace for the main method. Thanks, Alex