此问题已在此处找到答案:
什么是nullpointerexception,如何修复它((12个答案)
如何使用maven创建具有依赖关系的可执行jar((31个答案)
19小时前关门。
我已经在intellij中创建了swing gui应用程序,该应用程序在使用intellij运行时运行良好,我想知道如何创建jar或exe文件(无需安装),以便将其提供给想要使用它的人
我已经尝试了下面的方法,并且已经创建了jar,但是当单击jar时仍然没有发生任何事情
下面是app.java中的代码
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class App {
private JButton buttonMsg;
private JPanel panelMain;
public App() {
buttonMsg.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null,"Hello world");
}
});
}
private void createUIComponents() {
// TODO: place custom component creation code here
}
public static void main(String[] args) {
JFrame frame = new JFrame("App");
frame.setContentPane(new App().panelMain);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}
更新:
当使用java-jar命令运行jar时,它在buttonmsg.addactionlistener(newActionListener()行上给了我nullpointerexception{
jar还是不能运行
暂无答案!
目前还没有任何答案,快来回答吧!