Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can you explain how to display the dates and integer values between two dates using hashmap, and it should be displayed in listview in javafx.

Example: Suppose, I need the dates and values between 10-02-2017 and 20-02-2017, so that the dates and the values are displayed between those values only.

10-02-2017 10
11-02-2017 17
12-02-2017 15
.
.
.
20-02-2017 17

What I have tried:

This is the following code I've been trying but it's getting error

Java
@FXML
    private Map<Date,Integer> map=new HashMap<Date,Integer>();
    @FXML
    private ListView listview = new ListView();


            Date date1=new Date();
            Date date2=new Date();
            
            map.put(date1, 10);
            map.put(date2,20);
            
            listItems.add(map.get(date1));
            listItems.add(map.get(date2));
            
            for(Map.Entry<Date, Integer>entry: map.entrySet())
            {
                String d="Number of entries for "+entry.getKey().toString()+" = "+entry.getValue();
                listItems.add(d);
            }
             listview.setItems(listItems);
        }
Posted
Updated 20-Feb-17 0:47am
v2
Comments
Patrice T 20-Feb-17 5:20am    
And you plan to tell the error message and position ?
Adra@SRM 20-Feb-17 5:29am    
i'm getting error at :

listitems.add(map.get(date1));
listitems.add(map.get(date2));
Patrice T 20-Feb-17 5:39am    
And the error message ?
Use Improve question to update your question.
So that everyone can pay attention to this information.
Adra@SRM 20-Feb-17 5:47am    
sorry for that

error was :

listItems.add(map.get(date1));
method Collection.add(String) is not applicable
(argument mismatch; Integer cannot be converted to String)
method List.add(String) is not applicable
(argument mismatch; Integer cannot be converted to String)

1 solution

Java
listItems.add(map.get(date1));

Your call to map.get returns an integer value (10, 20 etc) but listItems.add requires a String.

As clearly stated in the error messages.
 
Share this answer
 
Comments
Adra@SRM 20-Feb-17 6:52am    
Thank you for your reply sir. Now I'm trying another statement for date which shown below:

LocalDate dateFrom=dpFrom.getValue();
LocalDate dateTo=dpTo.getValue();
LocalDate currentDate=dateFrom;
while (currentDate.isBefore(dateTo)){
map.put(currentDate, 0);
currentDate=currentDate+1;
}

but i'm getting error on the last line "currentDate=currentDate+1" saying that bad operand types for binary operator '+'.

What would be the solution for this?
Richard MacCutchan 20-Feb-17 7:25am    
The best solution would be to study the documentation for the Java Date class to see how to add 1 to the date.
Adra@SRM 24-Feb-17 4:00am    
ok thank you sir

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