IntelliJ idea gui designer + maven

匿名 (未验证) 提交于 2019-12-03 01:57:01

问题:

I have a project created with help of GUI designer. Here is code of main form.

public class MainForm {     MainForm() {         directLineOkButton.addActionListener(new ActionListener() {             public void actionPerformed(ActionEvent arg0) {                //some action                 }             }         });         crossLineOkButton.addActionListener(new ActionListener() {             public void actionPerformed(ActionEvent arg0) {                //some action         });         clearButton.addActionListener(new ActionListener() {             public void actionPerformed(ActionEvent arg0) {             //some action         });         cancelButton.addActionListener(new ActionListener() {             public void actionPerformed(ActionEvent arg0) {             //some action         });         saveButton.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent arg0) {           //some action         });     }      public JPanel getMainPanel() {         return mainPanel;     }      private void createUIComponents() {         drawingPanel = new DrawingPanel();     }      private JPanel mainPanel;     private JComboBox directDirectionCombobox;     private JButton directLineOkButton;     private JButton crossLineOkButton;     private JComboBox crossLineComboBox;     private JTextField crossLineSizeValue;     private JButton clearButton;     private JLabel directLineLabel;     private JPanel directLinePanel;     private JLabel crossLineLabel;     private JPanel crossLinePanel;     private JPanel okClearButtonPanel;     private JTextField directLineSizeValue;     private JButton saveButton;     private JPanel drawingPanel;     private JButton cancelButton; } 

It works fine. Jar file generates fine, here code of pom.xml

4.0.0DOCDOC1.0org.apache.poipoi3.9maven-compiler-plugin2.3.21.61.6org.apache.maven.pluginsmaven-jar-plugintrueMainmaven-assembly-pluginMainjar-with-dependencies

But when I try to run jar file there is a mistake.

Exception in thread "main" java.lang.NullPointerException at MainForm.(MainForm.java:14) at Main.main(Main.java:13) 

It show that mistake is at the line where directLineOkButton listener is created. I create listener like said here: http://www.jetbrains.com/idea/training/demos/GUI_Designer/GUI_Designer.html in constructor using cmd+o. Here is code of xml of form:

回答1:

You must include ideauidesigner-maven-plugin:

org.codehaus.mojoideauidesigner-maven-plugin1.0-beta-1javac2truetruetrue

and optionally - if you use GridLayoutManager or JGoodies - include also forms_rt as dependency:

    com.intellijforms_rt7.0.3


回答2:

I've found decision by myself. http://glxn.net/2010/08/17/making-a-swing-project-using-intellij-idea-and-gui-builder-with-maven-including-executable-jar/ You need special plugin to make maven projects with intelliji idea gui designer.



回答3:

I had the same problem with building my project with maven. What solved my problem was to change the value for "Generate GUI into:" from "Binary class files" --> "Java source code" in the settings (found in Project|Settings|Editor|GUI Designer).



回答4:

In your dynamic initializer (the part with the {{}}), you are accessing directLineOkButton:

directLineOkButton.addActionListener(new ActionListener() {             public void actionPerformed(ActionEvent arg0) {                //some action                 }             }         }); 

However, that field hasn't been assigned yet, so you get a NullPointerException.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!