NullPointerException in alphavantageServiceTesr

I am getting nullpointerexception in alphavantageServiceTest file.

I have mapped the string response to the alphavantageDailyResponse.

Then i iterated through the dates (from to) and used the function getCandles to get the hashmap of alphavantageCandle.

Then i used function of alphavantageCandle setDate (created by me) and set the date.
Then i added the object to Newly created arraylist.

Then casted it to candles and returned.
But something is going wrong.

Hi @vishalbihani2
Looks like you are facing challenges in the current module.

Below is a link to all the FAQ’s for the current module

Below are a few similar topics raised by other users which you might find usefull

Note - This is a BETA Feature,if you find this helpful, kindly let us know.
Feedback link -

Kindly mark this as a solution if this has helped you solve your query

You need to use debugger to find out which part of your code is causing the nullpointerexception, which variable is null. The stacktrace with the test that fails will be a good point to start.

now there is a different error.

I have added the ignoreProperty for the unknown fields.
Ignored the date field
also i have added jsonProperty for each field in the class.
but still this error.
what it is trying to say.

Why is my values null?

So after debugging i found that i was getting the candle List and it was not null. Then why i was getting null pointer exception when the test file was accessing the index 0 ?

now see the value of candle at index 0 and the assertion at line 68. What is the error then?


So basically, you need to use the right annotations to map the values from the API to the DTO since the keys will be different i.e. the name of field in API and its name in your object. Once you do it, you need to do same thing as you did with TiingoCandle. Read API response in a string form and use ObjectMapper to map that string to AlphavantageCandle[].class, which will give you an array of those objects.

i have use the correct notations.
for eg. “2. high”
but still getting error.
Why am i getting nullpointerException?

You need to use the stacktrace to find out where the exception is originating from and then use debugger to find which variable is null. Once you have that, it’ll be possible to resolve this error.

Closing this topic as your issue is resolved by the mentor. If it is still not resolved, Kindly un-mark the accepted solution or create a new topic and post this question as a reference link in the description of the new topic.