无法从JFileChooser向JLabel显示图像

时间:2013-07-12 13:13:59

标签: java swing nullpointerexception jlabel jfilechooser

代码

    public void actionPerformed (ActionEvent e) {
    JFileChooser fileChooser=new JFileChooser(); 

    int a=fileChooser.showOpenDialog(null);  
    if(a==JFileChooser.APPROVE_OPTION)  {

    FilefileToOpen=fileChooser.getSelectedFile();
    BufferedImage bi;

    try {
    bi = ImageIO.read(new File("C:\\Users\\nexboy94\\Desktop\\IT 2297- Object-Oriented Analysis and Design Project\\Refresh.png"));

    lblNewLabel_UploadResidentImageLabel.setIcon(new ImageIcon(bi));
    } catch (IOException e2) {
    e2.printStackTrace();
    }
    }
    }

错误就是这个

   Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
   at ui.CreateResident$8.actionPerformed(CreateResident.java:260)
   at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
   at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
   at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
   at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
   at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
   at java.awt.Component.processMouseEvent(Unknown Source)
   at javax.swing.JComponent.processMouseEvent(Unknown Source)
   at java.awt.Component.processEvent(Unknown Source)
   at java.awt.Container.processEvent(Unknown Source)
   at java.awt.Component.dispatchEventImpl(Unknown Source)
   at java.awt.Container.dispatchEventImpl(Unknown Source)
   at java.awt.Component.dispatchEvent(Unknown Source)
   at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
   at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
   at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
   at java.awt.Container.dispatchEventImpl(Unknown Source)
   at java.awt.Window.dispatchEventImpl(Unknown Source)
   at java.awt.Component.dispatchEvent(Unknown Source)
   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)

0 个答案:

没有答案