Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

"Method Name Required"

 
Alex Kirk
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's true, but even when I fixed that, my error persists. Any other thoughts?
Alex
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
::Very chagrined::
Yup, you were right. I'd accidentally placed it outside of the closing brace for the main method.
Thanks,
Alex
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic