RestTemplate.getForObject() throwing NullPointer Exception

I am extracting the symbols from trades.json as done in Module 1. Now for the url to get the respective json file for the stock details, I have it:

DateFormat df = new SimpleDateFormat("yyyy-mm-dd");

    Date endDate = df.parse(args[1]);

    String startDate = df.format(new Date(endDate.getTime() - 2));

    List<TiingoCandle> stocks = new ArrayList<TiingoCandle>();

    for (String symbol : symbols) {

      String link = ""+symbol.toLowerCase()+"/prices?startDate="+startDate;

      link += "&endDate="+endDate+"&token=8724bfe36e1998fd90b04181af883102b6dea8cb";

      //stocks.add(, HttpMethod.GET, entity, Candle.class).getBody());

      String result = restTemplate.getForObject(link, String.class);

      stocks.add(om.readValue(result, new TypeReference<TiingoCandle>(){}));


But on running it with the given input it is throwing NullPointer Exception at the line where getForObject is being called. The url is working on using it with cUrl though. The error being shown is:

> Task :qmoney:run FAILED
05:25:22.201 [main] ERROR com.crio.warmup.stock.log.UncaughtExceptionHandler - {"stacktrace":["com.crio.warmup.stock.PortfolioManagerApplication.mainReadQuotes(","com.crio.warmup.stock.PortfolioManagerApplication.main("],"cause":"java.lang.NullPointerException"}
java.lang.NullPointerException: null
        at com.crio.warmup.stock.PortfolioManagerApplication.mainReadQuotes( ~[main/:?]
        at com.crio.warmup.stock.PortfolioManagerApplication.main( ~[main/:?]

FAILURE: Build failed with an exception.

Hi @crazylazylife
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

Hi @crazylazylife,

You need to convert the date to string to use it in the uri for getForObject. You can do it directly by using inbuilt toString method of LocalDate objects. The startDate needs to be taken as the purchase date of the stock, as given in the TODO. The endDate should already be in a string format, so you can use it directly without converting it into a date object.

I changed the code to this, but its still throwing the same error:

Even if I hard code the dates, its still giving the exception there. I have checked the token and its correct. When I copy paste the whole command in command line with curl, it gives the desires result.

Please do not post any code here,
You have not assigned the access token properly from tiingo, can you recheck you api url,

In these cases where your API URL is correct or not, you can check with postman and see what result you are getting there

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.