.setIcon()导致NullPointerException

时间:2019-05-05 08:18:58

标签: java netbeans nullpointerexception

我正在编写一段不错的代码,效果很好。它无处不在停止了工作,我让其他人对其进行了测试,并确认它也不适用于他们。我还尝试回滚代码,甚至几天后也没有任何变化。我放了一堆System.out.Println()来帮助我调试代码在哪里中断并收到NullPointerException。它发生在initComponents()处。更奇怪的是,当我使用GUI Builder时,initComponenets中的任何内容都是使用NetBeans生成的。我只有15行,称为“ Alive#”,因此当程序崩溃时,我可以轻松地在日志中看到它们。崩溃之前我只能看到活着的14,从来没有达到活着的15。我只能在下面放一个片段。 https://pastebin.com/ibPfDxMY具有完整的initComponents()。更让人好奇的是,当从NetBeans运行它时,它始终如一地工作,只有当我通过双击或终端运行.jar文件时,才会出现此错误。

我尝试运行空白的测试框架,并且运行得很好。


public class NewFrame extends javax.swing.JFrame {

    public NewFrame() throws IOException, NullPointerException{
        System.out.println("Alive 14");
        initComponents();
        System.out.println("Alive 15");
    }


 private void initComponents() {

        mainPane = new javax.swing.JPanel();
        headerPane = new javax.swing.JPanel();
        logoButton = new javax.swing.JButton();
        exitButton = new javax.swing.JButton();
        titleLabel = new javax.swing.JLabel();
        logoutButton = new javax.swing.JButton();
        PacketPane = new javax.swing.JTabbedPane();
        exploitPane = new javax.swing.JPanel();
        exploitScroll = new javax.swing.JScrollPane();
        exploitList = new javax.swing.JList<>();
        customPane = new javax.swing.JPanel();
        customFrame = new javax.swing.JPanel();
        customScroll = new javax.swing.JScrollPane();
        customList = new javax.swing.JList<>();
        builderPane = new javax.swing.JPanel();
        builderFrame = new javax.swing.JPanel();
        builderPlaceholder = new javax.swing.JLabel();
        InfoPane = new javax.swing.JTabbedPane();
        logPane = new javax.swing.JPanel();
        logScroll = new javax.swing.JScrollPane();
        logArea = new javax.swing.JTextPane();
        chartPane = new javax.swing.JPanel();
        chartScroll = new javax.swing.JScrollPane();
        chartTable = new javax.swing.JTable();
        monsterPane = new javax.swing.JPanel();
        monsterScroll = new javax.swing.JScrollPane();
        monsterTable = new javax.swing.JTable();
        inventoryPane = new javax.swing.JPanel();
        inventoryScroll = new javax.swing.JScrollPane();
        inventoryList = new javax.swing.JList<>();
        bankPane = new javax.swing.JPanel();
        bankScroll = new javax.swing.JScrollPane();
        bankList = new javax.swing.JList<>();
        infoPane = new javax.swing.JPanel();
        infoFrame = new javax.swing.JPanel();
        goldValue = new javax.swing.JLabel();
        acValue = new javax.swing.JLabel();
        areaIdValue = new javax.swing.JLabel();
        entValue = new javax.swing.JLabel();
        usernameValue = new javax.swing.JLabel();
        areaValue = new javax.swing.JLabel();
        playerCountValue = new javax.swing.JLabel();
        playerCountLabel = new javax.swing.JLabel();
        areaLabel = new javax.swing.JLabel();
        usernameLabel = new javax.swing.JLabel();
        entLabel = new javax.swing.JLabel();
        areaIdLabel = new javax.swing.JLabel();
        acLabel = new javax.swing.JLabel();
        goldLabel = new javax.swing.JLabel();
        togglePane = new javax.swing.JPanel();
        toggleFrame = new javax.swing.JPanel();
        afkButton = new javax.swing.JButton();
        followButton = new javax.swing.JButton();
        farmButton = new javax.swing.JButton();
        slideButton = new javax.swing.JButton();
        invisibleButton = new javax.swing.JButton();
        copyButton = new javax.swing.JButton();
        copyLabel = new javax.swing.JLabel();
        invisibleLabel = new javax.swing.JLabel();
        slideLabel = new javax.swing.JLabel();
        farmLabel = new javax.swing.JLabel();
        followLabel = new javax.swing.JLabel();
        afkLabel = new javax.swing.JLabel();
        afkValue = new javax.swing.JLabel();
        followValue = new javax.swing.JLabel();
        farmValue = new javax.swing.JLabel();
        slideValue = new javax.swing.JLabel();
        invisibleValue = new javax.swing.JLabel();
        copyValue = new javax.swing.JLabel();
        SettingsPane = new javax.swing.JPanel();
        settingsFrame = new javax.swing.JPanel();
        userLabel = new javax.swing.JLabel();
        emoteLabel = new javax.swing.JLabel();
        settingsSubmitButton = new javax.swing.JButton();
        delayLabel = new javax.swing.JLabel();
        loopLabel = new javax.swing.JLabel();
        settingsSpamButton = new javax.swing.JButton();
        emoteList = new javax.swing.JComboBox<>();
        loopField = new javax.swing.JTextField();
        userField = new javax.swing.JTextField();
        textField = new javax.swing.JTextField();
        textLabel = new javax.swing.JLabel();
        delayField = new javax.swing.JTextField();
        ChatPane = new javax.swing.JPanel();
        chatScroll = new javax.swing.JScrollPane();
        chatArea = new javax.swing.JTextPane();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Yumemi");
        setUndecorated(true);

        mainPane.setBackground(new java.awt.Color(30, 30, 30));
        mainPane.setPreferredSize(new java.awt.Dimension(716, 567));
        mainPane.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                mainPaneMouseDragged(evt);
            }
        });
        mainPane.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                mainPaneMousePressed(evt);
            }
        });

        headerPane.setBackground(new java.awt.Color(0, 0, 0));

        logoButton.setBackground(new java.awt.Color(0, 0, 0));
        logoButton.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N
        logoButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/AQWBot/Icons/icon.png"))); // NOI18N
        logoButton.setBorder(null);
        logoButton.setBorderPainted(false);
        logoButton.setContentAreaFilled(false);
        logoButton.setDefaultCapable(false);
        logoButton.setFocusPainted(false);
        logoButton.setFocusable(false);
        logoButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        logoButton.setIconTextGap(0);
        logoButton.setRequestFocusEnabled(false);
        logoButton.setVerifyInputWhenFocusTarget(false);
        logoButton.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                logoButtonMouseDragged(evt);
            }
        });
        logoButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                logoButtonMousePressed(evt);
            }
        });

        exitButton.setBackground(new java.awt.Color(255, 0, 0));
        exitButton.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N
        exitButton.setForeground(new java.awt.Color(255, 255, 255));
        exitButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/aqwbot/Icons/close.jpg"))); // NOI18N
        exitButton.setText("X");
        exitButton.setBorderPainted(false);
        exitButton.setContentAreaFilled(false);
        exitButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        exitButton.setIconTextGap(0);
        exitButton.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/aqwbot/Icons/close_clicked.jpg"))); // NOI18N
        exitButton.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/aqwbot/Icons/close_hover.jpg"))); // NOI18N
        exitButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitButtonActionPerformed(evt);
            }
        });

        titleLabel.setFont(new java.awt.Font("Calibri", 1, 14)); // NOI18N
        titleLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        titleLabel.setText("Yumemi");
        titleLabel.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                titleLabelMouseDragged(evt);
            }
        });
        titleLabel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                titleLabelMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                titleLabelMouseExited(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                titleLabelMousePressed(evt);
            }
        });

        logoutButton.setBackground(new java.awt.Color(255, 102, 0));
        logoutButton.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N
        logoutButton.setForeground(new java.awt.Color(255, 255, 255));
        logoutButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/aqwbot/Icons/logout.jpg"))); // NOI18N
        logoutButton.setText("L");
        logoutButton.setBorderPainted(false);
        logoutButton.setContentAreaFilled(false);
        logoutButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        logoutButton.setIconTextGap(0);
        logoutButton.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/aqwbot/Icons/logout_clicked.jpg"))); // NOI18N
        logoutButton.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/aqwbot/Icons/logout_hover.jpg"))); // NOI18N
        logoutButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                logoutButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout headerPaneLayout = new javax.swing.GroupLayout(headerPane);
        headerPane.setLayout(headerPaneLayout);
        headerPaneLayout.setHorizontalGroup(
            headerPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(headerPaneLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(logoButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(titleLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(logoutButton, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(exitButton, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        headerPaneLayout.setVerticalGroup(
            headerPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(headerPaneLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(headerPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(headerPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(exitButton, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(titleLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(logoutButton, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(logoButton, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(0, 9, Short.MAX_VALUE))
        );

        exploitList.setModel(new javax.swing.AbstractListModel<String>() {
            String[] strings = { "Raw", "XP", "Say", "Whisper", "Role Play", "Emote", "", "Join", "Goto", "Move", "House", "", "Friend", "Follow", "Copy", "ID", "", "Party Chat", "Invite Party", "Remove Party", "Summon", "Promote", "Leave Party", "", "Guild Chat", "Create Guild", "Invite to Guild", "Remove from Guild", "Promote Guild", "Demote Guild", "Change MOTD", "Rename Guild", "", "Battle Commands", "", "Custom Commands", "Invisible", "Slide", "Farm", "Share Attack", "", "Staff Commands" };
            public int getSize() { return strings.length; }
            public String getElementAt(int i) { return strings[i]; }
        });
        exploitList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        exploitScroll.setViewportView(exploitList);

        javax.swing.GroupLayout exploitPaneLayout = new javax.swing.GroupLayout(exploitPane);
        exploitPane.setLayout(exploitPaneLayout);
        exploitPaneLayout.setHorizontalGroup(
            exploitPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(exploitPaneLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(exploitScroll, javax.swing.GroupLayout.DEFAULT_SIZE, 330, Short.MAX_VALUE)
                .addContainerGap())
        );
        exploitPaneLayout.setVerticalGroup(
            exploitPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, exploitPaneLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(exploitScroll, javax.swing.GroupLayout.DEFAULT_SIZE, 208, Short.MAX_VALUE)
                .addContainerGap())
        );

        PacketPane.addTab("Commands", exploitPane);

        customList.setModel(new javax.swing.AbstractListModel<String>() {
            String[] strings = { "Accept Quest", "AutoComplete Quest" };
            public int getSize() { return strings.length; }
            public String getElementAt(int i) { return strings[i]; }
        });
        customScroll.setViewportView(customList);

        javax.swing.GroupLayout customFrameLayout = new javax.swing.GroupLayout(customFrame);
        customFrame.setLayout(customFrameLayout);
        customFrameLayout.setHorizontalGroup(
            customFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(customFrameLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(customScroll, javax.swing.GroupLayout.DEFAULT_SIZE, 340, Short.MAX_VALUE)
                .addContainerGap())
        );
        customFrameLayout.setVerticalGroup(
            customFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, customFrameLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(customScroll, javax.swing.GroupLayout.DEFAULT_SIZE, 217, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout customPaneLayout = new javax.swing.GroupLayout(customPane);
        customPane.setLayout(customPaneLayout);
        customPaneLayout.setHorizontalGroup(
            customPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 360, Short.MAX_VALUE)
            .addGroup(customPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(customPaneLayout.createSequentialGroup()
                    .addGap(0, 0, Short.MAX_VALUE)
                    .addComponent(customFrame, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 0, Short.MAX_VALUE)))
        );
        customPaneLayout.setVerticalGroup(
            customPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 229, Short.MAX_VALUE)
            .addGroup(customPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(customPaneLayout.createSequentialGroup()
                    .addGap(0, 0, Short.MAX_VALUE)
                    .addComponent(customFrame, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 0, Short.MAX_VALUE)))
        );

        PacketPane.addTab("Custom", customPane);

        builderFrame.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        builderPlaceholder.setText("Accept Args and Data and Etc");

        javax.swing.GroupLayout builderFrameLayout = new javax.swing.GroupLayout(builderFrame);
        builderFrame.setLayout(builderFrameLayout);
        builderFrameLayout.setHorizontalGroup(
            builderFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(builderFrameLayout.createSequentialGroup()
                .addGap(66, 66, 66)
                .addComponent(builderPlaceholder, javax.swing.GroupLayout.PREFERRED_SIZE, 181, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(77, Short.MAX_VALUE))
        );
        builderFrameLayout.setVerticalGroup(
            builderFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(builderFrameLayout.createSequentialGroup()
                .addGap(77, 77, 77)
                .addComponent(builderPlaceholder)
                .addContainerGap(118, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout builderPaneLayout = new javax.swing.GroupLayout(builderPane);
        builderPane.setLayout(builderPaneLayout);
        builderPaneLayout.setHorizontalGroup(
            builderPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(builderPaneLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(builderFrame, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        builderPaneLayout.setVerticalGroup(
            builderPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(builderPaneLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(builderFrame, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        PacketPane.addTab("Packet Builder", builderPane);

        logScroll.setBackground(new java.awt.Color(50, 50, 50));
        logScroll.setForeground(new java.awt.Color(200, 200, 200));
        logScroll.setToolTipText("");

        logArea.setEditable(false);
        logArea.setBackground(new java.awt.Color(50, 50, 50));
        logArea.setContentType("text/pl"); // NOI18N
        logArea.setForeground(new java.awt.Color(200, 200, 200));
        logScroll.setViewportView(logArea);

        javax.swing.GroupLayout logPaneLayout = new javax.swing.GroupLayout(logPane);
        logPane.setLayout(logPaneLayout);
        logPaneLayout.setHorizontalGroup(
            logPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(logPaneLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(logScroll, javax.swing.GroupLayout.DEFAULT_SIZE, 325, Short.MAX_VALUE)
                .addContainerGap())
        );
        logPaneLayout.setVerticalGroup(
            logPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(logPaneLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(logScroll, javax.swing.GroupLayout.DEFAULT_SIZE, 208, Short.MAX_VALUE)
                .addContainerGap())
        );

        InfoPane.addTab("Packets", logPane);

        chartScroll.setBackground(new java.awt.Color(50, 50, 50));
        chartScroll.setForeground(new java.awt.Color(200, 200, 200));
        chartScroll.setToolTipText("");

        chartTable.setBackground(new java.awt.Color(50, 50, 50));
        chartTable.setForeground(new java.awt.Color(200, 200, 200));
        chartTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        chartScroll.setViewportView(chartTable);

        javax.swing.GroupLayout chartPaneLayout = new javax.swing.GroupLayout(chartPane);
        chartPane.setLayout(chartPaneLayout);
        chartPaneLayout.setHorizontalGroup(
            chartPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(chartPaneLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(chartScroll, javax.swing.GroupLayout.DEFAULT_SIZE, 325, Short.MAX_VALUE)
                .addContainerGap())
        );
        chartPaneLayout.setVerticalGroup(
            chartPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(chartPaneLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(chartScroll, javax.swing.GroupLayout.DEFAULT_SIZE, 217, Short.MAX_VALUE)
                .addContainerGap())
        );

        InfoPane.addTab("Chart", chartPane);

        monsterScroll.setBackground(new java.awt.Color(50, 50, 50));
        monsterScroll.setForeground(new java.awt.Color(200, 200, 200));
        monsterScroll.setToolTipText("");

        monsterTable.setBackground(new java.awt.Color(50, 50, 50));
        monsterTable.setForeground(new java.awt.Color(200, 200, 200));
        monsterTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        monsterScroll.setViewportView(monsterTable);

        javax.swing.GroupLayout monsterPaneLayout = new javax.swing.GroupLayout(monsterPane);
        monsterPane.setLayout(monsterPaneLayout);
        monsterPaneLayout.setHorizontalGroup(
            monsterPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(monsterPaneLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(monsterScroll, javax.swing.GroupLayout.DEFAULT_SIZE, 325, Short.MAX_VALUE)
                .addContainerGap())
        );
        monsterPaneLayout.setVerticalGroup(
            monsterPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(monsterPaneLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(monsterScroll, javax.swing.GroupLayout.DEFAULT_SIZE, 217, Short.MAX_VALUE)
                .addContainerGap())
        );

        InfoPane.addTab("Monster", monsterPane);

        inventoryList.setModel(new javax.swing.AbstractListModel<String>() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public String getElementAt(int i) { return strings[i]; }
        });
        inventoryScroll.setViewportView(inventoryList);


1 个答案:

答案 0 :(得分:0)

我认为此行会导致NullPointerException

logoButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/AQWBot/Icons/icon.png"))); // NOI18N

我也遇到了这个问题,例如,当我将整个路径传递到图像时,它就对我有用:(前提是图像位于软件包at.daselias.resources.icons中)

logoButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/at/daselias/resources/icons/icon.png"))); // NOI18N

总是仅在jar文件中而不是在IDE中发生该问题。

编辑:当然,要按我建议的行解决问题还不够,您必须在加载资源的所有行中都进行此操作。