Results 1 to 5 of 5
  1. #1
    the reporter is offline Member
    Join Date
    Jun 2010
    Posts
    17
    Rep Power
    0

    Default Unable to retrieve stock quotes from yahoo

    Hi all, im able to populate my file from textfile to the comboboxes however it's just not retriving data. What's wrong with my symbols? Can anyone help me troubleshoot this code? I want to retrive the stock quotes from the various company on my combobox. If i change the portion Stock.add(StockInfo[1] it can get the yahoo fiance data. however when i put it to Stock.add(StockInfo[1] and want to retrieve it using the name it cant be done. anyone can help?

    Java Code:
    import java.awt.BorderLayout;
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.net.URL;
    import java.util.ArrayList;
    import java.util.Scanner;
    
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    
    
    public class fyp6 {
    	JLabel label1 = new JLabel("Symbol: ");
    	JLabel label2 = new JLabel("Symbol: ");
    	JLabel label3 = new JLabel("Last price: ");
    	JLabel label4 = new JLabel("Change: ");
    	JLabel label5 = new JLabel("volume: ");
    	JLabel read1 = new JLabel("");
    	JLabel read2 = new JLabel("");
    	JLabel read3 = new JLabel("");
    	JLabel read4 = new JLabel("");
    	ArrayList<Object> Stock;
    	Object[] arr;
    	
    	public fyp6() {
    		 Stock  = new ArrayList<Object>();
    		  String line = null;
    		try
            {
                    FileInputStream fis = new FileInputStream(
                    		("C:/Java Sem 2/FYP SEM 1/stock.txt"));
                    InputStreamReader isr = new InputStreamReader(fis);
                    BufferedReader input = new BufferedReader(isr);
                    while ((line = input.readLine()) != null){
    	            	String[] StockInfo = line.split(",");  
    	            	Stock.add(StockInfo[0]);
    	            	
                    
                  
                    
                    
                    }   	
            }
            
            catch(FileNotFoundException FNF)
            {
                    System.err.println("File not found: " + FNF);
            }
            catch(IOException E)
            {
              System.err.println("IOException: " + E);  
            }
            
            
            arr = Stock.toArray();
            final JComboBox ipList = new JComboBox(arr);
           
            
            JFrame frame1 = new JFrame("stock");
    		frame1.setBounds(50, 50, 400, 200);
    
    		frame1.setLayout(new BorderLayout());
    		
    		JPanel panel1 = new JPanel();
    		JPanel panel2 = new JPanel();
    		panel1.setLayout(new GridLayout(1,2));
    		
    		 
    		 
    	
    		panel1.add(label1);
    		panel1.add(ipList);
    		panel2.setLayout(new GridLayout(4,2));
    		panel2.add(label2);
    		panel2.add(read1);
    		panel2.add(label3);
    		panel2.add(read2);
    		panel2.add(label4);
    		panel2.add(read3);
    		panel2.add(label5);
    		panel2.add(read4);
    		
    		frame1.add(panel1, BorderLayout.NORTH);
    		frame1.add(panel2, BorderLayout.CENTER);
    		
    		ipList.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e) {
    
    				try {
    			     	Object input1 =ipList.getSelectedItem(); 
    					URL yahoo = new URL("http://download.finance.yahoo.com/d/quotes.csv?s="+input1+"&f=sl1d1t1c1ohgv&e=.csv");
    					BufferedReader in = new BufferedReader(new InputStreamReader(yahoo.openStream()));
    					Scanner src = new Scanner(in).useDelimiter(",");;
    						
    					read1.setText(src.next());
    					read2.setText(src.next());
    					read3.setText(src.next());
    					read3.setText(src.next());
    					read3.setText(src.next());
    					read4.setText(src.next());
    					read4.setText(src.next());
    					read4.setText(src.next());
    					read4.setText(src.next());
    
    					in.close();
    							           
    				} catch (IOException ex) {
    					ex.printStackTrace();
    				
    				}
    			}
    		});
    		
    		
    		frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		frame1.setVisible(true);
    	    }
    	public static void main(String[] args) {
    		new fyp6();
    	}
    }
    Attached Files Attached Files
    Last edited by the reporter; 06-03-2010 at 07:26 AM.

  2. #2
    chyrl is offline Senior Member
    Join Date
    Mar 2010
    Location
    Manila, Philippines
    Posts
    257
    Rep Power
    5

    Default

    Double posted thread.
    Every project, package, class, method, variable, syntax, algorithm, etc.
    are registered in my memory bank. Thanks to this thread.

  3. #3
    the reporter is offline Member
    Join Date
    Jun 2010
    Posts
    17
    Rep Power
    0

    Default

    can anyone help?

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  5. #5
    chyrl is offline Senior Member
    Join Date
    Mar 2010
    Location
    Manila, Philippines
    Posts
    257
    Rep Power
    5

    Default

    Yes. The combobox help. It's almost the same content.
    Every project, package, class, method, variable, syntax, algorithm, etc.
    are registered in my memory bank. Thanks to this thread.

Similar Threads

  1. Need a Main for a Stock Managing program !!
    By Sary in forum New To Java
    Replies: 3
    Last Post: 05-30-2010, 07:57 PM
  2. Stock exchange program
    By askinne2 in forum New To Java
    Replies: 2
    Last Post: 05-02-2010, 11:25 PM
  3. String, quotes and args
    By mac in forum New To Java
    Replies: 8
    Last Post: 02-04-2010, 04:24 PM
  4. unbalanced quotes in -
    By fresh83 in forum New To Java
    Replies: 2
    Last Post: 12-19-2009, 01:10 AM
  5. Stock Quotes
    By BartDR in forum Advanced Java
    Replies: 0
    Last Post: 09-15-2009, 09:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •