java.util.NoSuchElementException: No value present

14:14:27.502 [main] ERROR com.crio.warmup.stock.log.UncaughtExceptionHandler - {“stacktrace”:[“
java:95)”,“com.crio.warmup.stock.PortfolioManagerApplication.main(”],“cause”:“java.util.NoSuchElementException: No value present”}
java.util.NoSuchElementException: No value present
at java.util.Optional.get( ~[?:1.8.0_242]
at com.crio.warmup.stock.PortfolioManagerApplication.mainReadQuotes( ~[main/:?]
at com.crio.warmup.stock.PortfolioManagerApplication.main( ~[main/:?]

Not able to solve. Please help me with it

Accoriding to me you are getting this error because in your code you are trying to fetch an element from the data structure which does not exist. Most probably i think the fault is in your loop iteration if you are using one.

It is because you are trying to fetch the element that is empty.
Hint: check whether the element is empty or not and if it is empty assign a default value to it.

any resource on how to do that ?
Please help

If the data is not available for closing date fetch the most recent available data

Hint: you can use recent data for example current date in place of endDate.
Hope this helps you

Hi @lakshmidurga2503 @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!