This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark ""Method Name Required"" Watch ""Method Name Required"" New topic
Author

"Method Name Required"

Alex Kirk
Ranch Hand

Joined: Aug 13, 2001
Posts: 44
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
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
That's true, but even when I fixed that, my error persists. Any other thoughts?
Alex
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

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
::Very chagrined::
Yup, you were right. I'd accidentally placed it outside of the closing brace for the main method.
Thanks,
Alex
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: "Method Name Required"