Results 1 to 8 of 8
- 10-11-2010, 05:22 PM #1
Member
- Join Date
- Sep 2010
- Posts
- 19
- Rep Power
- 0
problem filling list with values from CSV feed
afternoon,
i have this feed...
Java Code:package com.citi.blott; public class StockBean { String ticker; float price; float change; String chartUrlSmall; String chartUrlLarge; long lastUpdated; public void setTicker(String ticker) { this.ticker = ticker; } public String getTicker() { return ticker; } public float getPrice() { return price; } public void setPrice(float price) { this.price = price; } public float getChange() { return change; } public void setChange(float change) { this.change = change; } public String getChartUrlSmall() { return chartUrlSmall; } public void setChartUrlSmall(String chartUrlSmall) { this.chartUrlSmall = chartUrlSmall; } public String getChartUrlLarge() { return chartUrlLarge; } public void setChartUrlLarge(String chartUrlLarge) { this.chartUrlLarge = chartUrlLarge; } public long getLastUpdated() { return lastUpdated; } public void setLastUpdated(long lastUpdated) { this.lastUpdated = lastUpdated; } public Object[] asObjects() { return new Object[]{getTicker(), getPrice(), getChange()}; } }
Next is the code that parses the CSV feed!
Java Code:package com.citi.blott; import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; import java.util.Date; import java.util.HashMap; public class StockTickerDAO { //private static final Log log = LogFactory.getLog(StockTickerDAO.class); private static final StockTickerDAO stockDAO = new StockTickerDAO(); private static HashMap<String, StockBean> stocks = new HashMap<String, StockBean>(); private static final long TWENTY_MIN = 1200000; private StockTickerDAO() {} public static StockTickerDAO getInstance() { return stockDAO; } /** * * @param symbol * @return StockBean * will return null if unable to retrieve information */ public StockBean getStockPrice(String symbol) { StockBean stock; long currentTime = (new Date()).getTime(); // Check last updated and only pull stock on average every 20 minutes if (stocks.containsKey(symbol)) { stock = stocks.get(symbol); if(currentTime - stock.getLastUpdated() > TWENTY_MIN) { stock = refreshStockInfo(symbol, currentTime); } } else { stock = refreshStockInfo(symbol, currentTime); } return stock; } //This is synched so we only do one request at a time //If yahoo doesn't return stock info we will try to return it from the map in memory private synchronized StockBean refreshStockInfo(String symbol, long time) { try { URL yahoofin = new URL("http://finance.yahoo.com/d/quotes.csv?s=" + symbol + "&f=sl1d1t1c1ohgv&e=.csv"); URLConnection yc = yahoofin.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream())); String inputLine; while ((inputLine = in.readLine()) != null) { String[] yahooStockInfo = inputLine.split(","); StockBean stockInfo = new StockBean(); stockInfo.setTicker(yahooStockInfo[0].replaceAll("\"", "")); stockInfo.setPrice(Float.valueOf(yahooStockInfo[1])); stockInfo.setChange(Float.valueOf(yahooStockInfo[4])); stockInfo.setChartUrlSmall("http://ichart.finance.yahoo.com/t?s=" + stockInfo.getTicker()); stockInfo.setChartUrlLarge("http://chart.finance.yahoo.com/w?s=" + stockInfo.getTicker()); stockInfo.setLastUpdated(time); stocks.put(symbol, stockInfo); break; } in.close(); } catch (Exception ex) { System.out.println("Unable to get stockinfo for: " + symbol + ex); } return stocks.get(symbol); } }
I need to pass a value from this other class
Java Code:public class PriceListPopulator { List<StockBean> getPricesToPopulate() { List<StockBean> prices = new ArrayList<StockBean>(); [B][I][U]prices.add(new StockBean("msft"));[/U][/I][/B] return prices; }
When i change the constructor in the first example the like "stockInfo.setTicker(yahooStockInfo[0].replaceAll("\"", "")); " comes up with an error!!
But i keep getting an error on the line thats highlighted, saying "cannot find symbol" Does anyone have any idea why?
This method worked with an XML feed but isnt working for this CSV one.
Basically the resulting list is added to a JTable elsewhere
Thanks in advanceLast edited by shy_ted; 10-11-2010 at 05:25 PM.
- 10-12-2010, 09:01 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
You need to show us the exact error.
"Cannot find symbol" tells you what it can't find.
- 10-12-2010, 09:27 AM #3
Member
- Join Date
- Sep 2010
- Posts
- 19
- Rep Power
- 0
cannot find symbol
symbol constructor StockBean()
location com.citi.blott.StockBean()
it happens on this line
its something to do with these constructors...Java Code:StockBean stockInfo = new StockBean();
Java Code:public StockBean(String ticker) { this.ticker = ticker; }
but without this there are more errors.
- 10-12-2010, 09:49 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
You have a constructor declared that takes a String parameter.
You are trying to call a constructor with no parameter at all....StockBean does not have such a constructor.
- 10-12-2010, 09:55 AM #5
Member
- Join Date
- Sep 2010
- Posts
- 19
- Rep Power
- 0
yea, thats the thing, if i was to change it around, the errors would change too.
unless i can have two constructors, but i dont think that would do what i want it to do, as it seems to be called from 2 places!
- 10-12-2010, 09:57 AM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Well, I can't help you there since I have no idea what your requirements are.
You need to decide what it is StockBean requires to be created, and what can actually be supplied to StockBean at the point it's created.
- 10-12-2010, 10:04 AM #7
Member
- Join Date
- Sep 2010
- Posts
- 19
- Rep Power
- 0
hmm, ok
Basically, i have 3 class files working together and outputting the data to the output window as text, and i want them to be put into a JTable everytime the program is loaded.
Previously i had it loading from XML and it worked fine, so i thought just changing the source that fills the arraylist would do it, but it wont. is there any other way that i can show you what i have?
- 10-12-2010, 10:19 AM #8
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Similar Threads
-
How do I list values of an arrays in a comma seperted list
By nmvictor in forum New To JavaReplies: 2Last Post: 11-22-2009, 05:24 PM -
How do I list values of an arrays in a comma seperted list
By nmvictor in forum New To JavaReplies: 3Last Post: 11-21-2009, 05:48 PM -
I have a problem filling out this method
By kira137 in forum New To JavaReplies: 6Last Post: 10-11-2009, 01:43 AM -
trying to set() values of in list of arraylist
By alvations in forum New To JavaReplies: 15Last Post: 10-13-2008, 09:35 PM -
Getting values of an Option List
By mutuah in forum Advanced JavaReplies: 0Last Post: 08-07-2007, 03:42 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks