Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2011
    Posts
    16
    Rep Power
    0

    Default error: Constructor 'X' in Class 'X' cannot be applied to given types

    I've got this error but no idea how to solve it since theres no error in my Taxi class, the error message goes like this:

    required: no arguments
    found: String,String,boolean,char,double,double,int,int,S tring,String
    reason: actual and formal argument lists differ in length
    1 error

    and heres my taxi method:

    Java Code:
    public void Taxi(String licenseId, String typeOfVehicle, boolean supportWheelChair, char typeOfFuel,
      	               double speedOfVehicle, double costOfVehicle, int manufacturedYear, byte availableSeats,
      	               String nameOfDriver, String nextServicingDate)


    and my call to constructor :
    Java Code:
    Taxi t1 = new Taxi("SGH0095F", "Car", true, 'G', 300.0, 35249.0, 2011, 5, "Benny Wahano", "02/10/2011");


    The full code for Taxi class :
    Java Code:
     
    
    public class Taxi
    {
      //Grouped the variables according to variable type & declare them
      private byte numberOfSeats; 
      private int yearManufactured;
      private double vehicleSpeed;
      private double vehicleCost;
      private char fuelType; 
      private boolean wheelChairSupport; 
      private String vehicleType; 
      private String driverName;
      private String nextServiceDate; 
      private String licensePlate;
    
      public void Taxi(String licenseId, String typeOfVehicle, boolean supportWheelChair, char typeOfFuel,
      	               double speedOfVehicle, double costOfVehicle, int manufacturedYear, byte availableSeats,
      	               String nameOfDriver, String nextServicingDate)
      	         
      {
     
          numberOfSeats = availableSeats;
          yearManufactured = manufacturedYear;
          vehicleSpeed = speedOfVehicle;
          vehicleCost = costOfVehicle;
          fuelType = typeOfFuel;
          wheelChairSupport = supportWheelChair;
          vehicleType = typeOfVehicle;
          driverName = nameOfDriver;
          nextServiceDate = nextServicingDate;
          licensePlate = licenseId;
      }
    
    }
    and my main class :
    Java Code:
    public class Driver {
    
        public static void main(String []args)
        {
          Taxi t1 = new Taxi("SGH0095F", "Car", true, 'G', 300.0, 35249.0, 2011, 5, "Benny Wahano", "02/10/2011");
        }
    
    }
    Last edited by FiasseKrystella; 10-01-2011 at 09:29 PM.

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

    Default Re: error: Constructor 'X' in Class 'X' cannot be applied to given types

    The Taxi class has no true constructor, only a "pseudo" constructor. Remember that constructors don't have a return type, not void, not anything.

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,435
    Blog Entries
    7
    Rep Power
    20

    Default Re: error: Constructor 'X' in Class 'X' cannot be applied to given types

    [edit: too slow and wrong answer; I should go to bed ]

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    Join Date
    Aug 2011
    Posts
    16
    Rep Power
    0

    Default Re: error: Constructor 'X' in Class 'X' cannot be applied to given types

    Thanks, made a mistake there using 'void'.

    The error appears when I tried to pass the value of 5 as a byte argument but the compiler took my 5 as int???!?
    reason: actual argument int cannot be converted to byte by method invocation conversion

    didn't knew why this happened but I had to use casting to make it compile T_T

Similar Threads

  1. Replies: 1
    Last Post: 03-10-2010, 01:53 PM
  2. Replies: 0
    Last Post: 12-19-2007, 09:10 AM
  3. Replies: 0
    Last Post: 12-19-2007, 09:01 AM
  4. Error: cannot be applied to (java.lang.String)
    By carl in forum New To Java
    Replies: 1
    Last Post: 08-05-2007, 06:33 AM
  5. Replies: 1
    Last Post: 08-01-2007, 06:10 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
  •