0

I am trying to pull stock data from yahoo finance using the yahoo finance api for java. My program was working absolutely fine up until yesterday, when this piece of code just stopped working, throwing up the following errors:

SEVERE: Unparseable date: "11/17/2014"
java.text.ParseException: Unparseable date: "11/17/2014"
    at java.text.DateFormat.parse(DateFormat.java:337)
    at yahoofinance.Utils.parseDividendDate(Utils.java:176)
    at yahoofinance.quotes.stock.StockQuotesData.getDividend(StockQuotesData.java:87)
    at yahoofinance.quotes.stock.StockQuotesData.getStock(StockQuotesData.java:105)
    at yahoofinance.YahooFinance.getQuotes(YahooFinance.java:336)
    at yahoofinance.YahooFinance.get(YahooFinance.java:76)
    at yahoofinance.YahooFinance.get(YahooFinance.java:61)
    at controlp5userinterface.ControlP5UserInterface.setup(ControlP5UserInterface.java:75)
    at processing.core.PApplet.handleDraw(PApplet.java:2361)
    at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:240)
    at processing.core.PApplet.run(PApplet.java:2256)
    at java.lang.Thread.run(Thread.java:695)
Exception in thread "Animation Thread" java.lang.NullPointerException
    at controlp5userinterface.ControlP5UserInterface.setup(ControlP5UserInterface.java:76)
    at processing.core.PApplet.handleDraw(PApplet.java:2361)
    at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:240)
    at processing.core.PApplet.run(PApplet.java:2256)
    at java.lang.Thread.run(Thread.java:695)

Here is my code for the section that has stopped working, I can post the complete code if it is of any help. I know that the error is in parsing the date in the yahoo finance cvs file returned but I have no idea why its happening now when it worked perfectly beforehand.

Stock[] stocks = new Stock[symbols.length];
    double[] quotePrices = new double[stocks.length];
    for(int i = 0; i<stocks.length; i++){
        String symbol = symbols[i];
        stocks[i] = YahooFinance.get(symbol); //error is here
        quotePrices[i] = stocks[i].getQuote().getPrice().doubleValue();
        System.out.println("Price: " + quotePrices[i]);
    }
    System.out.println("Finished finance import");
4

1 回答 1

3

此问题已在 v1.2.3 中修复(同时 v1.3.0 可用,推荐使用)

此外,如果库无法解析股息日期,它将向日志文件写入错误(例如:SEVERE: Unparseable date: "11/17/2014"),但会捕获异常并且股息日期将只是null.

雅虎财经可能根本不返回任何股息日期,因此请null在尝试使用之前检查它是否是。

如果您遇到这样的问题,请不要犹豫,通过 Github 创建问题。

于 2015-03-14T14:30:45.217 回答