1
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);
    }


   } }

出于某种原因,这段代码给了我标题中给出的错误,然后是大量的异常列表。然后控制台加载,但没有数据加载,您必须将鼠标悬停在控制台的每个部分上才能显示。有什么帮助吗?

编辑:以下是例外情况:

线程“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) 在 javax.swing.plaf.synth.SynthTableUI.paintCell(SynthTableUI.java:684) 在 javax.swing.plaf.synth.SynthTableUI.paintCells(SynthTableUI.java:581) ) 在 javax.swing.plaf.synth.SynthTableUI.paint(SynthTableUI.java:365) 在 javax.swing.plaf.synth.SynthTableUI.update(SynthTableUI.java:276) 在 javax.swing.JComponent.paintComponent(JComponent. java:778) 在 javax.swing.JComponent.paint(JComponent.java:1054) 在 javax.swing.JComponent.paintChildren(JComponent.java:887) 在 javax.swing.JComponent.paint(JComponent.java:1063) 在javax.swing.JViewport.paint(JViewport.java:725) 在 javax.swing.JComponent.paintChildren(JComponent.java:887) 在 javax.swing.JComponent.paint(JComponent.java:1063) 在 javax.swing.JComponent.paintChildren(JComponent.java:887) 在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) 在 javax.swing.JComponent.paint(JComponent.java:1063) 在 javax.swing.JComponent.paintChildren(JComponent.java:887) 在 javax.swing.JComponent.paint(JComponent. java:1063) 在 javax.swing.JLayeredPane.paint(JLayeredPane.java:585) 在 javax.swing.JComponent.paintChildren(JComponent.java:887) 在 javax.swing.JComponent.paintToOffscreen(JComponent.java:5228) 在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) 在 java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:39) 在 sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:78) 在 sun.awt.SunGraphicsCallback.runComponents( SunGraphicsCallback.java:115) 在 java.awt.Container.paint(Container.java:1967) 在 java.awt.Window.paint(Window.java:3867) 在 javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:781 ) 在 javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:728) 在 javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:677) 在 javax.swing.RepaintManager.access$700(RepaintManager.java:59) 在 javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1621) 在 java.awt.event.InvocationEvent.dispatch(InvocationEvent.java: 251) 在 java.awt.EventQueue.dispatchEventImpl(EventQueue.java:705) 在 java.awt.EventQueue.access$000(EventQueue.java:101) 在 java.awt.EventQueue$3.run(EventQueue.java:666) 在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) 在 java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211) 在 java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128) 在 java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117) 在 java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113) 在 java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105) 在 java. awt.EventDispatchThread.run(EventDispatchThread.java:90) 线程“AWT-EventQueue-0”中的异常 java.lang.ArrayIndexOutOfBoundsException: javax.swing.JTable$1.getValueAt(JTable.java:689) 处 javax.swing 中的 1。 JTable.getValueAt(JTable.java:2720) 在 javax.swing.JTable.prepareRenderer(JTable.java:5718) 在 javax.swing.plaf.synth.SynthTableUI.paintCell(SynthTableUI.java:684) 在 javax.swing.plaf .synth.SynthTableUI.paintCells(SynthTableUI.java:581) 在 javax.swing.plaf.synth.SynthTableUI.paint(SynthTableUI.java:365) 在 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) 在 javax.swing.JComponent.paint(JComponent.java:1063) 在 javax.swing.JViewport.paint(JViewport.java:725) 在 javax.swing.JComponent.paintChildren(JComponent.java:887) 在 javax .swing.JComponent.paint(JComponent.java:1063) 在 javax.swing.JComponent.paintChildren(JComponent.java:887) 在 javax.swing.JComponent.paint(JComponent.java:1063) 在 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) 在 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) 在 javax.swing.JComponent.paintToOffscreen(JComponent.java:5228) 在 javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1482) 在 javax.swing.RepaintManager$PaintManager.paint(RepaintManager. java:1413) 在 javax.swing.RepaintManager.paint(RepaintManager.java:1206) 在 javax.swing.JComponent.paint(JComponent.java:1040) 在 java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:39) )在 sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:78) 在 sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:115) 在 java。awt.Container.paint(Container.java:1967) 在 java.awt.Window.paint(Window.java:3867) 在 javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:781) 在 javax.swing.RepaintManager.paintDirtyRegions (RepaintManager.java:728) 在 javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:677) 在 javax.swing.RepaintManager.access$700(RepaintManager.java:59) 在 javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager .java:1621) 在 java.awt.Event.InvocationEvent.dispatch(InvocationEvent.java:251) 在 java.awt.EventQueue.dispatchEventImpl(EventQueue.java:705) 在 java.awt.EventQueue.access$000(EventQueue.java :101) 在 java.awt.EventQueue$3.run(EventQueue.java:666) 在 java.awt.EventQueue$3.run(EventQueue.java:664) 在 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) ) 在 java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128) 在 java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117) 在 java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113) 在 java.awt .EventDispatchThread.pumpEvents(EventDispatchThread.java:105) 在 java.awt.EventDispatchThread.run(EventDispatchThread.java:90)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) 在 java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105) 在 java.awt.EventDispatchThread.run(EventDispatchThread.java:90)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) 在 java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105) 在 java.awt.EventDispatchThread.run(EventDispatchThread.java:90)awt.EventDispatchThread.run(EventDispatchThread.java:90)awt.EventDispatchThread.run(EventDispatchThread.java:90)

4

2 回答 2

0

这条线

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

可能是错误的。selectedRow将无效。

于 2013-01-04T11:45:07.840 回答
0

堆栈跟踪应该向您显示错误所在的确切行。这是你最好的线索。

默认情况下应该包含行号,但如果看不到它们,则使用 (javac -g) 上的调试信息重新编译。

于 2013-01-04T11:49:27.773 回答