由于NullPointerException,我的可执行jar文件无法运行

时间:2011-01-18 08:20:07

标签: java nullpointerexception executable-jar

我正在尝试将我的项目打包成可运行的jar文件,我收到了这个错误:


Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at javax.swing.ImageIcon.<init>(Unknown Source)
    at eBridge.LoginPage.initialize(LoginPage.java:66)
    at eBridge.LoginPage.<init>(LoginPage.java:55)
    at eBridge.LoginPage.<init>(LoginPage.java:49)
    at eBridge.eBridgFrame.<init>(eBridgFrame.java:37)
    at eBridge.eBridgFrame$1.run(eBridgFrame.java:24)
    at java.awt.event.InvocationEvent.dispatch(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)

我的主要方法是在类calss eBridgFrame上,并且itz在选项卡上运行...这里是eBridgFrame类:


package eBridge;

import javax.swing.SwingUtilities;
import java.awt.BorderLayout;

import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.WindowEvent;

import javax.swing.WindowConstants;

public class eBridgFrame extends JFrame {

 private static final long serialVersionUID = 1L;
 private JPanel jContentPane = null;


 public static void main(String[] args) {
  SwingUtilities.invokeLater(new Runnable() {
   public void run() {
    eBridgFrame thisClass = new eBridgFrame();
    thisClass.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
    thisClass.setVisible(true);
   }
  });
 }

 /**
  * This is the default constructor
  */
 public eBridgFrame() {
  super();
  initialize();
  JPanel panel = new LoginPage(this);
  this.getContentPane().add(panel);
  this.setVisible(true);
 }

 /**
  * This method initializes this
  * 
  * @return void
  */
 private void initialize() {
  this.setSize(950, 720);
  this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
  this.setName("EBRIDG");
  this.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/eBridge/images/eB.png")));
  this.setResizable(false);
  this.setMinimumSize(new Dimension(950, 720));
  this.setPreferredSize(new Dimension(950, 720));
  this.setContentPane(getJContentPane());
  this.setTitle("EBRIDG");
  }
 //Pop up msg to confirm closing by overiding javax.swing.JFrame.processWindowEvent() method
   protected void processWindowEvent(WindowEvent e) {

          if (e.getID() == WindowEvent.WINDOW_CLOSING) {

              int exit = JOptionPane.showConfirmDialog(this, "Are you sure?");
              if (exit == JOptionPane.YES_OPTION) {
                  System.exit(0);
              }

          } 
 }

 /**
  * This method initializes jContentPane
  * 
  * @return javax.swing.JPanel
  */
 private JPanel getJContentPane() {
  if (jContentPane == null) {
   jContentPane = new JPanel();
   jContentPane.setLayout(new BorderLayout());
  }
  return jContentPane;
 }

}

有人能救我吗???非常感谢!

2 个答案:

答案 0 :(得分:3)

如果你告诉我们哪一行是第66行,那真的会有所帮助,但我的猜测就是这样:

this.setIconImage(Toolkit.getDefaultToolkit().getImage(
    getClass().getResource("/eBridge/images/eB.png")));

听起来你的jar文件中没有包含eB.png,或者你没有将它包含在正确的位置。

答案 1 :(得分:1)

您需要查看以下行;

 eBridge.LoginPage.initialize(LoginPage.java:66)