当前位置: 首页 > 知识库问答 >
问题:

Java线程“AWT-EventQueue-0”中的Java异常。lang.ArrayIndexOutofBounds异常:1

姚飞昂
2023-03-14
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);
    }


   } }

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

编辑:以下是例外:

共有2个答案

巩阳秋
2023-03-14

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

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

陆弘光
2023-03-14

这条线

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

selectedRow将无效。

 类似资料: