1
votes
public class ConsoleControl {

private static Viewer mainGUI;

public static Viewer getMainGUI()
{
    return mainGUI;        
}
    public static void main(String[] args){
    // Imports the Java UI Manager, which allows you to change the basic GUI of the Application
    try { 
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); 
    } 
    catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
}
    MainModel.setPetShop(FileIO.readPetShop("PetShop.csv"));
    MainModel.setPets(FileIO.readPets("Pets.csv"));
    MainModel.setFish(FileIO.readFish("Fish.csv"));

    MainModel.setPetShopHeader(new String[]{"Name","Address","Phone Number","Website","Opening Times"});
    MainModel.setPetsHeader(new String[]{"Shop","Type","Price","Date Acquired","Notes"});
    MainModel.setFishHeader(new String[]{"Shop","Type","Price","Date Acquired","Latin Name","Food Requirements"});
    mainGUI = new Viewer();
    mainGUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

  public static void actOnTableClick(int selectedRow)
{
    ArrayList<Integer> attRowsToHighlight = new ArrayList<>();
    if (mainGUI.getSelectedTab() == 0)
    {
        PetShop ourPetShop = MainModel.getPetShop().get(selectedRow);

        for (int i = 0; i < MainModel.getPets().size(); i++)
        {
            Pets ourPets = MainModel.getPets().get(i);

            if (ourPets.getShop().equals(ourPetShop.getName()))
            {
              //  System.out.print(ourPets);
                attRowsToHighlight.add(i);
               // System.out.print(i);
            }
        }
        mainGUI.highlightRows(1, attRowsToHighlight);
    }


   } }

For some reason, this piece of code gives me the error given in the title, and then a massive list of exceptions. The console then loads, but none of the data loads, and you have to hover over every section of the console to get it to show. Any help?

Edit: Here are the exceptions:

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 1 at javax.swing.JTable$1.getValueAt(JTable.java:689) at javax.swing.JTable.getValueAt(JTable.java:2720) at javax.swing.JTable.prepareRenderer(JTable.java:5718) at javax.swing.plaf.synth.SynthTableUI.paintCell(SynthTableUI.java:684) at javax.swing.plaf.synth.SynthTableUI.paintCells(SynthTableUI.java:581) at javax.swing.plaf.synth.SynthTableUI.paint(SynthTableUI.java:365) at javax.swing.plaf.synth.SynthTableUI.update(SynthTableUI.java:276) at javax.swing.JComponent.paintComponent(JComponent.java:778) at javax.swing.JComponent.paint(JComponent.java:1054) at javax.swing.JComponent.paintChildren(JComponent.java:887) at javax.swing.JComponent.paint(JComponent.java:1063) at javax.swing.JViewport.paint(JViewport.java:725) at javax.swing.JComponent.paintChildren(JComponent.java:887) at javax.swing.JComponent.paint(JComponent.java:1063) at javax.swing.JComponent.paintChildren(JComponent.java:887) at javax.swing.JComponent.paint(JComponent.java:1063) at javax.swing.JComponent.paintChildren(JComponent.java:887) at javax.swing.JComponent.paint(JComponent.java:1063) at javax.swing.JComponent.paintChildren(JComponent.java:887) at javax.swing.JComponent.paint(JComponent.java:1063) at javax.swing.JComponent.paintChildren(JComponent.java:887) at javax.swing.JComponent.paint(JComponent.java:1063) at javax.swing.JLayeredPane.paint(JLayeredPane.java:585) at javax.swing.JComponent.paintChildren(JComponent.java:887) at javax.swing.JComponent.paintToOffscreen(JComponent.java:5228) at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1482) at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1413) at javax.swing.RepaintManager.paint(RepaintManager.java:1206) at javax.swing.JComponent.paint(JComponent.java:1040) at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:39) at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:78) at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:115) at java.awt.Container.paint(Container.java:1967) at java.awt.Window.paint(Window.java:3867) at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:781) at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:728) at javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:677) at javax.swing.RepaintManager.access$700(RepaintManager.java:59) at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1621) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:705) at java.awt.EventQueue.access$000(EventQueue.java:101) at java.awt.EventQueue$3.run(EventQueue.java:666) at java.awt.EventQueue$3.run(EventQueue.java:664) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76) at java.awt.EventQueue.dispatchEvent(EventQueue.java:675) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105) at java.awt.EventDispatchThread.run(EventDispatchThread.java:90) Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 1 at javax.swing.JTable$1.getValueAt(JTable.java:689) at javax.swing.JTable.getValueAt(JTable.java:2720) at javax.swing.JTable.prepareRenderer(JTable.java:5718) at javax.swing.plaf.synth.SynthTableUI.paintCell(SynthTableUI.java:684) at javax.swing.plaf.synth.SynthTableUI.paintCells(SynthTableUI.java:581) at javax.swing.plaf.synth.SynthTableUI.paint(SynthTableUI.java:365) at javax.swing.plaf.synth.SynthTableUI.update(SynthTableUI.java:276) at javax.swing.JComponent.paintComponent(JComponent.java:778) at javax.swing.JComponent.paint(JComponent.java:1054) at javax.swing.JComponent.paintChildren(JComponent.java:887) at javax.swing.JComponent.paint(JComponent.java:1063) at javax.swing.JViewport.paint(JViewport.java:725) at javax.swing.JComponent.paintChildren(JComponent.java:887) at javax.swing.JComponent.paint(JComponent.java:1063) at javax.swing.JComponent.paintChildren(JComponent.java:887) at javax.swing.JComponent.paint(JComponent.java:1063) at javax.swing.JComponent.paintChildren(JComponent.java:887) at javax.swing.JComponent.paint(JComponent.java:1063) at javax.swing.JComponent.paintChildren(JComponent.java:887) at javax.swing.JComponent.paint(JComponent.java:1063) at javax.swing.JComponent.paintChildren(JComponent.java:887) at javax.swing.JComponent.paint(JComponent.java:1063) at javax.swing.JLayeredPane.paint(JLayeredPane.java:585) at javax.swing.JComponent.paintChildren(JComponent.java:887) at javax.swing.JComponent.paintToOffscreen(JComponent.java:5228) at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1482) at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1413) at javax.swing.RepaintManager.paint(RepaintManager.java:1206) at javax.swing.JComponent.paint(JComponent.java:1040) at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:39) at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:78) at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:115) at java.awt.Container.paint(Container.java:1967) at java.awt.Window.paint(Window.java:3867) at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:781) at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:728) at javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:677) at javax.swing.RepaintManager.access$700(RepaintManager.java:59) at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1621) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:705) at java.awt.EventQueue.access$000(EventQueue.java:101) at java.awt.EventQueue$3.run(EventQueue.java:666) at java.awt.EventQueue$3.run(EventQueue.java:664) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76) at java.awt.EventQueue.dispatchEvent(EventQueue.java:675) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105) at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

2
Which line throws the exception ?Brian Agnew
Have edited the first post with a list of the exceptions!user1396743

2 Answers

0
votes

This line

PetShop ourPetShop = MainModel.getPetShop().get(selectedRow);

is probably faulty. selectedRow will be invalid.

0
votes

The stack trace should show you the exact line that the error is on. This is your best clue.

The line numbers should be included by default, but if you can't see them then recompile with debug info on (javac -g).