Results 1 to 4 of 4
  1. #1
    Fate is offline Member
    Join Date
    Mar 2012
    Posts
    2
    Rep Power
    0

    Default Invalid method declaration; return type required

    hey guys, in need of a bit of java help.
    i seem to be getting an "Invalid method declaration; return type required" error when trying to set the return function on the getCarMake.

    Any help or guidance in the right direction would be greatly appreciated.

    this is the object class.

    Java Code:
    class Toy_Car
    {
    		private String car_make;
    		private int car_value;
    		private String car_details;
    
    	//constructor
    		public Toy_Car(String m, int v, String d)
    		{
    			car_make = m;
    			car_value = v;
    			car_details = d;
    		}
    
    		public void setCarMake(String cm)
    		{
    			this.car_make = cm;
    		}
    
    		public getCarMake()
    		{
    			return this.car_make;
    		}
    }
    And this is the main.
    the search function is only searching for the car make until this problem is solved.

    Java Code:
    public class java
    {
    	public static void main(String[] args)
    	{
    			String s;
    			int i = 0;
    			int newentry = 0;
    			int counter = 0;
    			int choice = 0;
    			String k = null;
    			int l = 0;
    			int search;
    
    			//set array length
    			int arraylength = 0;
    			s = JOptionPane.showInputDialog(null,"How many cars are there going to be in your collection?");
    			arraylength = Integer.parseInt(s);
    
    
    			//object array
    			Toy_Car[] x = new Toy_Car[arraylength];
    
    		while(counter == 0)
    		{
    			s = JOptionPane.showInputDialog(null,"Toy Car Collection" + '\n' + '\n' +
    				"(1):  Input new entry" + '\n' +
    				"(2):  Search");
    
    			choice = Integer.parseInt(s);
    
    			//input
    			if(choice == 1)
    			{
    				if(newentry < arraylength)
    				{
    					for(i = 0; i < arraylength; i++)
    					{
    						String make = JOptionPane.showInputDialog("enter the make of the car");
    						int value = Integer.parseInt(JOptionPane.showInputDialog("enter the value of the car"));
    						String colour = JOptionPane.showInputDialog("enter the colour of the car");
    					    x[i] = new Toy_Car(make,value,colour);
    					}
    
    					newentry++;
    				}
    				else
    				{
    					JOptionPane.showMessageDialog(null,"The array has been filled");
    				}
    			}
    
    			//search
    				if(choice == 2)
    			{
    				s = JOptionPane.showInputDialog(null,"what do you want to search?" + '\n' + '\n' +
    												    "1:  The make" + '\n' +
    												    "2:  The value" + '\n' +
    												    "3:  The colour");
    				search = Integer.parseInt(s);
    
    			//search by make
    				if(search == 1)
    				{
    					search_car_make = JOptionPane.showInputDialog(null,"Enter the car's make");
    
                  	  	temp = 0;
    
    					for(i = 0; i < arraylength; i++)
    					{
    						if(search_car_make.equals(x[i].car_make))
    						{
    							JOptionPane.showMessageDialog(null,"Entry" + ": " + (i + 1) + '\n' +
    															   "car make : " + x[i].car_make + '\n' +
    															   "car value : " +	" " + x[i].car_value + '\n' +
    															   "car colour : " + x[i].car_colour);
    							temp++;
    						}
    					}
    
    					if(temp == 0)
    						{
    							JOptionPane.showMessageDialog(null,"The car your are searching for could not be found");
    						}
    				}
    		}
    	}
    }
    }
    this is the error.
    Java Code:
    public getCarMake()
    		{
    			return this.car_make;
    		}
    error message
    invalid method declaration; return type required

    I'm also using JCreator if that matters.
    Last edited by Fate; 03-08-2012 at 03:45 AM.

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Invalid method declaration; return type required

    The message pretty much means what it says: you *must* give the method a return type:

    Java Code:
    public ReturnTypeGoesHere getCarMake()
      {
        return this.car_make;
      }
    The return type will be whatever this.car_make was declared to be.

  3. #3
    Fate is offline Member
    Join Date
    Mar 2012
    Posts
    2
    Rep Power
    0

    Thumbs up Re: Invalid method declaration; return type required

    Quote Originally Posted by pbrockway2 View Post
    The message pretty much means what it says: you *must* give the method a return type:

    Java Code:
    public ReturnTypeGoesHere getCarMake()
      {
        return this.car_make;
      }
    The return type will be whatever this.car_make was declared to be.
    ah rookie error.

    cheers mate, appreciate it

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Invalid method declaration; return type required

    You're welcome.

Similar Threads

  1. invalid method declaration; return type required
    By DeclareVariablesNotWar in forum New To Java
    Replies: 10
    Last Post: 12-13-2011, 03:57 AM
  2. Replies: 2
    Last Post: 08-23-2011, 11:43 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

Posting Permissions

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