Have made this program that should open an image on my desktop but it gives me the error java.lang.ArrayIndexOutOfBoundsException when I run it. What I done wrong?
import java.awt.BorderLayout; import java.awt.image.BufferedImage; import java.io.File; import javax.imageio.ImageIO; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.SwingUtilities; import javax.swing.WindowConstants; public class Image { public static void main(String[] args) throws Exception { new Image(args[0]); } public Image(final String filename) throws Exception { SwingUtilities.invokeLater(new Runnable() { public void run() { JFrame editorFrame = new JFrame("C:/Users/Username/Desktop/index.jpg"); editorFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); BufferedImage image = null; try { image = ImageIO.read(new File(filename)); } catch (Exception e) { e.printStackTrace(); System.exit(1); } ImageIcon imageIcon = new ImageIcon(image); JLabel jLabel = new JLabel(); jLabel.setIcon(imageIcon); editorFrame.getContentPane().add(jLabel, BorderLayout.CENTER); editorFrame.pack(); editorFrame.setLocationRelativeTo(null); editorFrame.setVisible(true); } }); } What do I get this error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at Image.main(Image.java:15) 