NoSuchElementException

I am using this to pass the closing price which is a double as a parameter to TotalReturnsDto object to filter the list
But its giving me a nosuchelementexception
I tried using .isPresent() and .orElse(null)
But they are incompatible with it as the whole line is returning a double value
Been stuck here since very long
Please help

Can you post of the screenshot of the error that you are getting , I am not able to understand what your query is

Its happening because you are using optional, and data is not available on the end-date. You must be running it for 2020-01-01, which is a trading holiday.

Try running it for 2020-01-02, and you will get the data.
Of course you need to fix this error, where data is not present :slight_smile:

should i change the value of EndDate to another value ?

You can try that to confirm that its the same error.
I recommend you to change the logic so that if the data is not present on end-datem, you fall back to latest available data, as mentioned in the TODO

use the latest available data prior to the closing date

Hi @disha,

This error basically means that you tried fetching data for a given date but it doesn’t exist.

The solution to this is given in the TODOs themselves. You can combine the condition of data existing on given date as well not existing on given date by simply ensuring you always use data of the last date for which it is available and since the response contains data only for available dates, I leave it to you to figure out which element at which position of array needs to be used here.

I hope that helps!

1 Like

I’m closing this topic due to no response from anyone since last 12 hours. If your query is resolved you can mark any reply as a solution. If you still have the query, please create a new topic paste the link of this topic in the description.