0

以下のコードは、NetBeansIDEからの実行で正常に機能します

 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)

plsヘルプ

4

1 に答える 1

2

getResource()呼び出しによって返されたものを確認する

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

パスが正しい「ims」ではなく、「imgs」である可能性があります

于 2013-03-11T11:12:04.053 に答える