Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Java Duration Class, cannot resolve to a type

I am trying to find the difference in time between two LocalTime objects in HH:MM:SS format and my duration object is giving me the error Duration.between cannot be resolved to a type. The between description on Java docs explicitly says LocalTime objects are valid- do I have to translate my objects into LocalDateTime objects with zones for Duration to work?

Only other theory on this issue would be my placement of this class in my Make file, but I would think my import would take care of the issue during compilation. Code below:

import java.time.*;
import java.time.Duration;


public class Station {
    int stationNumber;
    String stationAddress;
    ArrayList<Driver> drivers;
    ArrayList<Road> roads;          
    double[][] roadMap;             

    public Station(int sNumber, String sAddress) {
        stationNumber = sNumber;
        stationAddress = sAddress;
        drivers = new ArrayList<Driver>();
        
        roads = new ArrayList<Road>(5);
        roadMap = new double[5][5];
    }

    public static void calculateNewTimes(ArrayList<roadDataToBeSorted> delDataIncreasingTime) {
        LocalTime firstStop = LocalTime.parse(delDataIncreasingTime.get(0).rdDeliveryTime);
        LocalTime lastStop = LocalTime.parse(delDataIncreasingTime.get(delDataIncreasingTime.size()-1).rdDeliveryTime);
        Duration duration = new Duration.between(firstStop, lastStop); ***<-----ISSUE***

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

between is s static method of Duration class, so you don’t need to create Duration object using the new keyword.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading