0

我的以下代码在从 NetBeans IDE 运行时运行良好

 public Selector() {
        try {

            if (count == 0) {
                initComponents();
                count++;
                ims.CPool.configureConnPool();
                fillTable();
                setResizable(false);
                Dimension Size = Toolkit.getDefaultToolkit().getScreenSize();
                setLocation(new Double((Size.getWidth() / 2) - (getWidth() / 2)).intValue(), new Double((Size.getHeight() / 2) - (getHeight() / 2)).intValue());
                jTable1.addMouseListener(this);
                img = ImageIO.read(Selector.class.getResource("/ims/Icons/login.png"));
                sci = img.getScaledInstance(jLabel3.getWidth(), jLabel3.getHeight(), java.awt.Image.SCALE_SMOOTH);
                ImageIcon newIconImage = new javax.swing.ImageIcon(sci);

                jLabel3.setIcon(newIconImage);

            } else {
                throw new myExc("Only one instance of the application is allowed to run at a time !");
            }
        } catch (HeadlessException | IOException | myExc x) {
            x.printStackTrace();
            JOptionPane.showMessageDialog(null,x.getMessage());
        }
    }

每当我尝试启动具有上述构造函数的类时,都会出现如下所示的异常

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: input
 == null!
        at javax.imageio.ImageIO.read(Unknown Source)
        at ims.init.Selector.<init>(Selector.java:60)
        at ims.init.Selector$8.run(Selector.java:502)
        at java.awt.event.InvocationEvent.dispatch(Unknown Source)
        at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
        at java.awt.EventQueue.access$000(Unknown Source)
        at java.awt.EventQueue$3.run(Unknown Source)
        at java.awt.EventQueue$3.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Sour
ce)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)

请帮忙

4

1 回答 1

2

检查getResource()调用返回的内容

img = ImageIO.read(Selector.class.getResource("/ims/Icons/login.png"));

可能是路径不正确“ims”但可能是“imgs”

于 2013-03-11T11:12:04.053 回答