Results 1 to 12 of 12
  1. #1
    Join Date
    Mar 2009
    Posts
    62
    Rep Power
    0

    Default [SOLVED] Undeclared Return Type for Method?

    Hey Guys,

    I'm having huge problems with this java malarky! I wonder if you can help.

    I'm very very basic with Java.

    I'm trying to write a simple method (code below):

    /**
    * Clears the calculator.
    */
    public void clear()
    {
    this.operand1Frog.setPosition(0);
    }

    As far as I understand it, this should work - I am access setPosition method from another class. When I execute clear(). I get the following error message:

    Semantic error: Error loading command: : Error loading script: Sourced file: /bsh/commands/clear.bsh : (Strict Java Mode) Undeclared return type for method: clear

    I just want to set the positions of the frogs to 0. Also if I copy this line:

    this.operand1Frog.setPosition(0); and place in the constructor it works fine and moves the Frog to position (0) with no problems.

    If you need futher information please let me know.

    All the best - FMJ.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    How do you "execute" this command?

  3. #3
    Join Date
    Mar 2009
    Posts
    62
    Rep Power
    0

    Default

    well as far as I am aware its clear();

    It then returns the error message as above and does not move the frog.

    I'm sure this will be a simple fix. I've only just started learning this.

    Cheers - FMJ.

  4. #4
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    7

    Default

    does setPosition return anything? That's the only thing I can see that might cause a return type error.
    Liberty has never come from the government.
    Liberty has always come from the subjects of government.
    The history of liberty is the history of resistance.
    The history of liberty is a history of the limitation of governmental power, not the increase of it.

  5. #5
    Join Date
    Mar 2009
    Posts
    62
    Rep Power
    0

    Default

    Hey xcallmejudasx,

    Not that I am aware of. The setPosition method (within the Frog Class) is shown below:

    /**
    * Sets the position of the receiver to the value of the argument aPosition.
    */
    public void setPosition (int aPosition)
    {
    this.position = aPosition;
    this.update("position");

    The strange thing is that if the line:

    this.operand1Frog.setPosition(0); is placed within the constructor it works fine and moves the frog as requested?

    Cheers -FMJ.

  6. #6
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    7

    Default

    are you trying to run this program through some sort of JavaScript function? What IDE(if any) are you using, and how are you compiling and executing it(command line, ide, etc)

    Your method is correct syntax wise. It is a void method so it can't have a return type(which it doesn't).

    I think the issue might be with using "this".

    operand1Frog is a frog object correct? If so you should only need this.setPosition(0)

    right now your code is saying this(which is the current object).someObject.methodOfThatObject ...which doesn't really make sense.
    Liberty has never come from the government.
    Liberty has always come from the subjects of government.
    The history of liberty is the history of resistance.
    The history of liberty is a history of the limitation of governmental power, not the increase of it.

  7. #7
    Join Date
    Mar 2009
    Posts
    62
    Rep Power
    0

    Default

    Hey xjudas,

    I'm using JDE version 2.1.3... but as I understand it, this software has been tailored for my course.

    Yes operand1Frog is a frog object, but if I change the code to:

    this.setPostion(1);

    I get the error message:

    cannot find symbol - method setPosition(int)? This might be because the method setPosition is within the Frog class not the FrogCalculator class that I am working on.

    I'm really sorry, its hard to explain being so new to this.

    All the best - FMJ.

  8. #8
    Mr.Beans's Avatar
    Mr.Beans is offline Senior Member
    Join Date
    Apr 2009
    Location
    Virginia Beach, Virginia
    Posts
    149
    Rep Power
    0

    Default

    How big is the program? Maybe you could post more relevant code.

    Also you are getting the error because the object "this" which is the object you are in when you call "this" does not have a method setPosition(int). The frog class does however. If you have an instance of a frog in you class then you could just do myFrog.setPosition(0);

    For example
    Java Code:
    public class Example
    {
         private Frog myFrog = null;
         
         public Example()
         {
               myFrong = new Frog();
         }
    
         public void clear()
         {
              myFrog.setPosition(0);
         }
    }
    I think that is similar to what you are trying to do. However, I'm still not completely sure on what your trying to accomplish.

    Mr. Beans

  9. #9
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Does anyone find the phrasing of the error message odd?
    Semantic error: Error loading command: : Error loading script: Sourced file: /bsh/commands/clear.bsh : (Strict Java Mode) Undeclared return type for method: clear
    error loading script? it's as if it is not related to the clear method but some other clear script? I'm afraid that it confuses me and perhaps this whole issue. Is it just me?

  10. #10
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    that does seem odd...

    @ fullmetaljacket: try it with a different method name. Depending on what your class is, it may be overriding something, though I doubt it

    @ Mr.Beans: It should be fine. The this may be unnecessary, but he is still accessing the Frog object.
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

  11. #11
    Mr.Beans's Avatar
    Mr.Beans is offline Senior Member
    Join Date
    Apr 2009
    Location
    Virginia Beach, Virginia
    Posts
    149
    Rep Power
    0

    Default

    I know that the "this" keyword did not make a difference in the original program, but I was responding to
    Yes operand1Frog is a frog object, but if I change the code to:

    this.setPostion(1);

    I get the error message:
    Still I don't think we can successfully solve this problem unless he's a little more clear on what he is trying to do and gives us some of the actual source code.

  12. #12
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    To the original poster: are you going to post anything here to clear any of this muddle up? Your code doesn't use anything involved with BeanShell, by the way, does it?

Similar Threads

  1. Replies: 3
    Last Post: 06-05-2010, 09:05 PM
  2. Method return type problem
    By McChill in forum New To Java
    Replies: 7
    Last Post: 05-05-2009, 10:21 PM
  3. Replies: 4
    Last Post: 11-25-2008, 06:53 AM
  4. The return type
    By Marcus in forum New To Java
    Replies: 1
    Last Post: 07-05-2007, 07:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •