使用命令行执行类时的异常

时间:2013-03-11 10:56:48

标签: java swing

我的下面代码在从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)

请帮助

1 个答案:

答案 0 :(得分:2)

查看getResource()电话

返回的内容
img = ImageIO.read(Selector.class.getResource("/ims/Icons/login.png"));

可能是这条道路不正确&#34; ims&#34;但可能是&#34; imgs&#34;