Results 1 to 5 of 5
Thread: Exception issues...
- 02-10-2010, 09:42 PM #1
Member
- Join Date
- Feb 2010
- Posts
- 2
- Rep Power
- 0
Exception issues...
Hi, I am having an exception issue here. If anyone could point me in the right direction here I would be very grateful. It seems like it has something to do with the version of the JRE that I use? I really don't understand where to even begin fixing this. Is there anywhere you would recommend I look to find this particular exception?
Java Code:import javax.swing.JFrame; public class myMessin{ public static void main (String args[]){ GUI2 go = new GUI2(); go.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); go.setSize(300,200); go.setVisible(true); GUI2 file = new GUI2("arrayRecord.txt"); file.showFile(); } }Java Code:import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.*; import java.util.ArrayList; import java.util.List; import javax.swing.*; public class GUI2 extends JFrame { private JButton first; private JButton prev; private JButton next; private JButton last; public int index = 0; private List<String> lines; private int currentIndex; private JFrame textFrame; public GUI2() { super("Inventory Program Part 5"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); lines = new ArrayList<String>(); setLayout(new FlowLayout()); first = new JButton("First"); add(first); prev = new JButton("Previous"); add(prev); next = new JButton("Next"); add(next); last = new JButton("Last"); add(last); HandlerClass handler = new HandlerClass(); first.addActionListener(handler); prev.addActionListener(handler); next.addActionListener(handler); last.addActionListener(handler); } public GUI2(String arrayRecord) { this(); try { BufferedReader reader = new BufferedReader(new FileReader( arrayRecord)); String line = ""; while ((line = reader.readLine()) != null) { lines.add(line); } } catch (Exception ex) { ex.printStackTrace(); } } public void showFile() { for (int i = 0; i < lines.size(); i++) { System.out.println(lines.get(i)); } } public static void main(final String[] args) { try { SwingUtilities.invokeAndWait(new Runnable() { public void run() { GUI2 f = new GUI2(args[0]); f.setSize(200, 200); f.setVisible(true); } }); } catch (Exception e) { System.out.println("Error"); } } private class HandlerClass implements ActionListener { public void actionPerformed(ActionEvent event) { textFrame = new JFrame("Inventory"); textFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); textFrame.getContentPane(); JTextArea textArea = new JTextArea(); textFrame.add(textArea); Object button = event.getSource(); if (first == button) { currentIndex = 0; } else if ((prev == button) && (currentIndex > 0)) { --currentIndex; } else if (next == button) { ++currentIndex; // Wrap if (currentIndex == lines.size()) { currentIndex = 0; } } else if (last == button) { currentIndex = lines.size() - 1; } textArea.setText(lines.get(currentIndex)); textFrame.setSize(200, 150); textFrame.setVisible(true); } } }
My errors are:
Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Index: 1, Size: 0
at java.util.ArrayList.RangeCheck(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
at GUI2$HandlerClass.actionPerformed(GUI2.java:112)
at javax.swing.AbstractButton.fireActionPerformed(Unk nown Source)
at javax.swing.AbstractButton$Handler.actionPerformed (Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed (Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent( Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(U nknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unkno wn Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Thanks in advance for any help :)
- 02-10-2010, 10:11 PM #2
Senior Member
- Join Date
- Nov 2009
- Posts
- 235
- Rep Power
- 4
You are trying to access an empty arraylist
- 02-11-2010, 02:03 AM #3
Member
- Join Date
- Feb 2010
- Posts
- 2
- Rep Power
- 0
Thanks
Is that possibly because I deleted the class that loaded the original array into the file? or because I didn't read the file correctly?
-
- 02-11-2010, 02:39 AM #5
Senior Member
- Join Date
- Nov 2009
- Posts
- 235
- Rep Power
- 4
Similar Threads
-
Exception in thread "main" java.lang Exception In InitializerError
By kenzo2009 in forum New To JavaReplies: 4Last Post: 10-25-2010, 07:42 PM -
jdk issues
By artemff in forum New To JavaReplies: 3Last Post: 01-02-2010, 03:18 AM -
Trouble with factory method - unhandled exception type Exception
By desmond5 in forum New To JavaReplies: 1Last Post: 03-08-2008, 06:41 PM -
Issues with Jva I.O
By Annatar01 in forum New To JavaReplies: 0Last Post: 02-08-2008, 01:16 AM -
Issues with a while loop
By Lang in forum New To JavaReplies: 4Last Post: 11-09-2007, 09:01 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks