Click here to Skip to main content
15,884,537 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all,
I havent converted the particular piece of code to int or even defined it as strings, yet it is saying that im trying to convert it to int. this is the current code I have and any help would be appreciated

Holiday h1 = new Holiday("Hull", 14, 8);
Holiday h2 = new Holiday("Bermuda", 2, 800);
Holiday h3 = new Holiday("Los Angeles", 19, 1900);
h3.setcost(2100);
h3.setDuration(12);
Holiday h4 = new Holiday();
h4.setcost(370);
h4.setDestination("Pyongyang");
h4.setDuration(7);
Posted
Comments
CPallini 25-Jun-15 4:48am    
How could we possibly help without knowing how Holiday class is defined?
Richard MacCutchan 25-Jun-15 4:48am    
Where does the error occur, and what is the definition of the class and the method throwing the error?
Adamdew93 25-Jun-15 5:16am    
sorry about that the holiday class is public ArrayList<holiday> Hols = new ArrayList<>(); // Creates an array list called Hols uses object Holiday to fill it

public Holiday(int NewDuration, String NewDestination, int newcost) { // Creates a method called Address with two variables (NewNumber / NewPostcode)
Duration = NewDuration;
Destination = NewDestination;
cost = newcost;

and what do you mean by definition of the class and method throwing the error
Richard MacCutchan 25-Jun-15 6:11am    
Your parameters are in the wrong order. You have int, String, int, but in your constructor you are passing a String as the first one.

1 solution

Check the definitions of the Holiday constructor, and the Holiday.SetDestination methods (depending on which line the error occurs on).

In the first case, you need a constructor that takes three parameters: string, int, int
In the second, you need a version that take a string, not an int.
 
Share this answer
 
v2
Comments
Adamdew93 25-Jun-15 6:00am    
I also have an error on this code Holiday h4 = new Holiday(); on the main class file
can you shed any light on why im getting this but what you mentioned above worked so thanks ps it says that constructor in holiday class cant be used
OriginalGriff 25-Jun-15 6:11am    
Do you have a constructor that takes no parameters? If not... :laugh:
Adamdew93 25-Jun-15 6:15am    
I dont think I do haha but how should it be coded if you can give me an example that would be excellent
OriginalGriff 25-Jun-15 6:26am    
If you don't have a constructor that takes no parameters, then you can't construct it!
You need to create a constructor, and have it set "dummy" values - or use the parameterised version you use in the other code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900