Results 1 to 5 of 5
  1. #1
    NeonPhoenix is offline Member
    Join Date
    Sep 2012
    Posts
    2
    Rep Power
    0

    Default Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0

    Im currently programming a small online shop program and i keep getting this error
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
    at shop.main(shop.java:54)

    and here is the code

    the error shows on line 54 in eclipse but its line 53 here

    Java Code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.sql.SQLException;
    
    public class shop extends JFrame {
    
    	private static final long serialVersionUID = 1L;
    	
    	mysqlServer factory;
    	JTextField query;
    	JTable table;
    	JLabel msgline;
    	
    	public shop(mysqlServer f) {
    		query = new JTextField();
    		table = new JTable();
    		msgline = new JLabel();
    		
    		Container contentPane = getContentPane();
    		contentPane.add(query, BorderLayout.NORTH);
    		contentPane.add(new JScrollPane(table), BorderLayout.CENTER);
    		contentPane.add(msgline, BorderLayout.SOUTH);
    		
    		query.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e) {
    				displayQueryResults(query.getText());
    			}
    		});
    	}
    	
    	public void displayQueryResults(final String q) {
    		msgline.setText("Contacting Database...");
    		
    		EventQueue.invokeLater(new Runnable() {
    			public void run() {
    				try {
    					table.setModel(factory.getProductList(q));
    					msgline.setText("");
    				}catch(SQLException ex) {
    					msgline.setText("");
    					JOptionPane.showMessageDialog(shop.this, new String[] {
    							ex.getClass().getName() + ": ",
    							ex.getMessage()
    					});
    				}
    			}
    		});
    	}
    	
        public static void main(String args[]) throws Exception {
    
        	mysqlServer factory = new mysqlServer(args[0], args[1], args[2], args[3]);
    
        	shop qf = new shop(factory);
    
        	qf.setSize(500, 600);
        	qf.setVisible(true);
        }
    }

  2. #2
    killutch is offline Member
    Join Date
    Sep 2012
    Posts
    70
    Rep Power
    0

    Default Re: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0

    well it looks like when the program runs you require 4 parameters. I haven't really used the args for the public static void main class but I would assume you would need to call it via command line and have 4 arguments when calling it. thats really only a guess though considering I haven't coded with the String[] args

  3. #3
    jfabian is offline Member
    Join Date
    Jun 2012
    Posts
    22
    Rep Power
    0

    Default Re: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0

    Its exactly what killutch says. You need the run the program with the respective parameters.

  4. #4
    NeonPhoenix is offline Member
    Join Date
    Sep 2012
    Posts
    2
    Rep Power
    0

    Default Re: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0

    How would i do that???

  5. #5
    RichersooN is offline Senior Member
    Join Date
    Jan 2011
    Location
    Rizal Province, Philippiines
    Posts
    167
    Rep Power
    0

    Default Re: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0

    You should review your code under mysqlServer class if the parameter are necessary:
    Java Code:
    mysqlServer factory = new mysqlServer(args[0], args[1], args[2], args[3]);

Similar Threads

  1. Replies: 1
    Last Post: 02-27-2012, 10:11 PM
  2. Replies: 4
    Last Post: 02-02-2011, 05:32 AM
  3. Replies: 4
    Last Post: 10-13-2010, 10:19 AM
  4. Replies: 1
    Last Post: 11-20-2009, 08:58 PM
  5. Replies: 1
    Last Post: 07-25-2007, 11:55 PM

Posting Permissions

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