Results 1 to 11 of 11
  1. #1
    Join Date
    Dec 2011
    Location
    H-Town baby
    Posts
    4
    Rep Power
    0

    Default invalid method declaration; return type required

    Im pretty new to Java (Taking my first class, AP Computer Science no less)
    The assignment is to write a graphical program that features the property of inheritance and uses constructors.
    Im drawing a creeper from minecraft, ive been tryin to troubleshoot it but im stumped
    help please?

    __________________________________________________ ________________
    Java Code:
    import java.awt.*;
    import java.applet.*;
    public class lab09 extends Applet
    {
    	public void paint(Graphics g)
    	{
    		MinecraftCreeper jack = new MinecraftCreeper(g);
    
    	}
    }
    
    class MinecraftCreeper extends Creeper
    {
    
    	public MinecraftCreeper(Graphics g)
    
    	{
    		super(g);
    	}
    }
    class Creeper
    {
    	public Creeper(Graphics g)
    	{
    		g.setColor(new Color(136,192,109));
    		g.fillRect(400,60,100,100);
    		g.setColor(new Color(0,0,0));
    		g.fillRect(420,80,20,20);
    		g.fillRect(460,80,20,20);
    		g.fillRect(440,100,20,30);
    		g.fillRect(430,110,10,30);
    		g.fillRect(460,110,10,30);
    	}
    }
    class CreeperTorso extends Torso
    {
    	public Torso(Graphics g)
    	{
    		g.setColor(new Color(0,0,0));
    		g.fillRect(40,80,20,20);
    	}
    }
    Last edited by Norm; 12-13-2011 at 03:11 AM. Reason: added code tags

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default Re: invalid method declaration; return type required

    Can you show the error message you ends up with?

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default Re: invalid method declaration; return type required

    Inside the CreeperTorso class how can you define this?

    Java Code:
    public Torso(Graphics g)
        {
            g.setColor(new Color(0,0,0));
            g.fillRect(40,80,20,20);
        }
    Do you know really what it is?

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default Re: invalid method declaration; return type required

    Java Code:
    class CreeperTorso extends Torso {
         public Torso(Graphics g)
    Hmmm!

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default Re: invalid method declaration; return type required

    Quote Originally Posted by Junky View Post
    Java Code:
    class CreeperTorso extends Torso {
         public Torso(Graphics g)
    Hmmm!
    What is extend does and how the constructor use. ;) Let see OP could find that.

  6. #6
    Join Date
    Dec 2011
    Location
    H-Town baby
    Posts
    4
    Rep Power
    0

    Default Re: invalid method declaration; return type required

    OK i cant believe i missed that....thanks for pointing it out guys! i have it now

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default Re: invalid method declaration; return type required

    You are welcome.

    BTW, are you working on with an IDE?

  8. #8
    Join Date
    Dec 2011
    Location
    H-Town baby
    Posts
    4
    Rep Power
    0

    Default Re: invalid method declaration; return type required

    yeah Im using JCreator

  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default Re: invalid method declaration; return type required

    I haven't use JCreator. But most of the time IDE give a lots of hints. I just compiled your code in NetBeans, and it give the following.

    error: invalid method declaration; return type required
    public Torso(Graphics g)
    1 error
    So looking at the pointed line of code, I can get some sense about the error. :) I believe that JCreator does the same.

  10. #10
    Join Date
    Dec 2011
    Location
    H-Town baby
    Posts
    4
    Rep Power
    0

    Default Re: invalid method declaration; return type required

    Quote Originally Posted by Eranga View Post
    I haven't use JCreator. But most of the time IDE give a lots of hints. I just compiled your code in NetBeans, and it give the following.



    So looking at the pointed line of code, I can get some sense about the error. :) I believe that JCreator does the same.
    Yeah, it does, I dont know i just blanked out I guess when I was trying to figure out what was wrong. Haha, like I said though im a total newbie at this.

  11. #11
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default Re: invalid method declaration; return type required

    Of course. With the practice you'll be able to catch those things. :) Same here when I start to coding.

    May be that is one of the advantages that stick into one or two IDEs. Then you know from A-Z. Anyway, good luck with Java.

Similar Threads

  1. Replies: 2
    Last Post: 08-23-2011, 11:43 PM
  2. JavaBean - invalid method declaration and return type required
    By jprog in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 05-07-2011, 07:13 PM
  3. Invalid Method Declaration; Return Type Required
    By bremzb in forum AWT / Swing
    Replies: 3
    Last Post: 05-05-2011, 11:12 PM
  4. Err: invalid method declaration; return type required
    By Die The Villain in forum New To Java
    Replies: 12
    Last Post: 04-15-2011, 01:44 AM
  5. invalid method declaration; return type required
    By XaviannNJ in forum JCreator
    Replies: 7
    Last Post: 11-25-2010, 02:59 PM

Tags for this Thread

Posting Permissions

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