Results 1 to 6 of 6
  1. #1
    ruben381 is offline Member
    Join Date
    Jan 2012
    Posts
    13
    Rep Power
    0

    Exclamation Requesting error help for my game.

    Hello everyone,

    I just started development on a small strategy game using Java, I'm also fairly new to Java itself.

    I'm getting an error when I try to return an int. I'll post the code here.


    Java Code:
    package src;
    
    public class Warrior extends Function {
    
    	public Warrior(int i) {
    		super(i);
    	}
    	public int isWarrior;
    	{
    		return true;
    	}
    }


    Where it says 'return true' is erroring.

    Here's the code for Function.

    Java Code:
    package src;
    
    public class Function extends Base{
    
    	public Function(int i) {
    		super(i);
    	}
    	
    	public boolean isWarrior;
    	{
    	
    	}
    	
    
    }




    Can anyone help me? :/

    The error is: Void methods cannot return a value

    But there are no void methods!!!

  2. #2
    ezkatz19 is offline Member
    Join Date
    Jan 2012
    Posts
    7
    Rep Power
    0

    Default Re: Requesting error help for my game.

    I think it's that you are supposed to return an int yet you return true, which is a reserved word for a boolean, and I know those types have to match.
    Is true supposed to be a variable for you? If so, you have to change its name
    Last edited by ezkatz19; 01-27-2012 at 04:53 AM.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is online now Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,235
    Rep Power
    19

    Default Re: Requesting error help for my game.

    Your return statement isn't inside any method. Note that a method signature always has a pair of parentheses ( ) -- either with the parameter list inside, or empty for a method that doesn't take any parameters.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is online now Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,235
    Rep Power
    19

    Default Re: Requesting error help for my game.

    Quote Originally Posted by ezkatz19 View Post
    I think it's that you are supposed to return an int yet you return true, which is a reserved word for a boolean, and I know those types have to match.
    Is true supposed to be a variable for you? If so, you have to change its name
    No, the preceding line declares a public int variable. And true is a reserved keyword, so can't be used as an identifier.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default Re: Requesting error help for my game.

    There's several things wrong.
    You define isWarrior as:
    Java Code:
    public boolean isWarrior() {}
    in Function, then change it to:
    Java Code:
    public int isWarrior() {}
    in the class extending Function. You can't change the type of the return value of a method.

    You have a misplaced ';' (as Darryl has pointed out) as well.

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is online now Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,235
    Rep Power
    19

    Default Re: Requesting error help for my game.

    Locking this thread as the OP deleted content from his second thread.

    db

    THREAD CLOSED
    Last edited by DarrylBurke; 04-27-2012 at 04:10 AM.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Requesting Code Review
    By Zeramat in forum New To Java
    Replies: 9
    Last Post: 06-16-2011, 05:59 AM
  2. Requesting help on tweeking a JCheckBox JList
    By benjamin.b in forum New To Java
    Replies: 4
    Last Post: 06-07-2011, 02:45 PM
  3. Requesting a review of my LoginBox!
    By aadem in forum New To Java
    Replies: 4
    Last Post: 03-16-2011, 09:01 PM
  4. Help getting my program to continue requesting info.
    By antdilla22 in forum New To Java
    Replies: 4
    Last Post: 09-13-2009, 10:44 PM
  5. Replies: 1
    Last Post: 06-23-2008, 06:46 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
  •