1 Replies - 513 Views - Last Post: 15 January 2009 - 01:05 PM Rate Topic: -----

#1 Bredge  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 105
  • Joined: 14-December 08

Missing Return statement

Posted 15 January 2009 - 12:48 PM

I have been staring at this for a few hours now and cannot workout why it is saying when I go to compile it "Missing Return Statement"... This is probably very simple for yous so forgive me for asking such as basic question.

Here is what I have as a method. I know the if else at the minute doesn't incorporate the Dialog request, im trying to cut the code down and then work it out from there.

public int moveRight(int steps)
   {
	  String inputString;
	  int currentPosition;
	  inputString = WIDialog.request("How many times should the reciever jump?","3");
	  steps = Integer.parseInt(inputString);
	  currentPosition = this.getPosition();
	  if((currentPosition >=1) && (currentPosition <=16)) 
	  {
	  
	  this.setColour(WIColour.YELLOW);
	  }
	  else 
	  {
		 
	  this.setColour(WIColour.RED);
   }


Cheers in advance

This post has been edited by leegt5: 15 January 2009 - 12:51 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Missing Return statement

#2 Gloin  Icon User is offline

  • Expert Schmexpert...
  • member icon

Reputation: 235
  • View blog
  • Posts: 4,489
  • Joined: 04-August 08

Re: Missing Return statement

Posted 15 January 2009 - 01:05 PM

The keyword int in

public int moveRight(int steps)

means you intend to return a value of type int when the method is invoked. In this case as you really don't need to return anything from the method, you should use the keyword void which signals you don't intend to return anything. You still need to end the method with the command return; though.

Btw, what's the point in having a parameter value sent to the method if you just overwrite it anyways?

public int moveRight(int steps) {
...
steps = Integer.parseInt(inputString);


This post has been edited by Gloin: 15 January 2009 - 01:03 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1