简体   繁体   English

使用IntelliJ IDEA GUI Designer在$$$ setupUI $$$上的NullPointer异常

[英]NullPointer Exception at $$$setupUI$$$ using IntelliJ IDEA GUI Designer

I've been trying to use a GUI I made in IntelliJ IDEAS GUI Designer in an applet I'm working on. 我一直在尝试在我正在使用的applet中使用我在IntelliJ IDEAS GUI Designer中创建的GUI。 I've gotten the thing to run when I just have one label inside my root JPanel but for some reason when I add more components I get the following error: 当我在我的根JPanel中只有一个标签但是由于某种原因当我添加更多组件时,我得到了运行的东西我得到以下错误:

java.lang.NullPointerException
at java.awt.Container.addImpl(Container.java:1095)
at java.awt.Container.add(Container.java:971)
at inputGui.$$$setupUI$$$(inputGui.java)
at inputGui.<init>(inputGui.java:25)
at HelloWorld.init(HelloWorld.java:11)
at sun.applet.AppletPanel.run(AppletPanel.java:435)
at java.lang.Thread.run(Thread.java:745)

My class for the GUI inputGui.java is laid out like this: 我的GUI inputGui.java类是这样布局的:

(I will mark the line where it breaks with: //!BROKEN - Line 25! ) (我将标记它打破的行: //!BROKEN - 第25行!

public class inputGui extends JFrame {
private JPanel rootNode;
private JTextField id_field;
private JTextField mi_field;
private JTextField lastName_field;
private JTextField address_field;
//more declorations...

public inputGui() {//initialize GUI
        super( "Hello World" );
        setContentPane( rootNode );//!BROKEN - Line 25!
        pack();
        setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
        setVisible( false );
    }
    public JPanel getRootNode() {
        return rootNode;
    }
    private void createUIComponents() {
        // TODO: place custom component creation code here
    }
}

And I call it from my Applets 'init()' function: 我从我的Applets的init()函数中调用它:

public class HelloWorld extends JApplet {
    //Called when this applet is loaded into the browser.
    public void init() {
        //Execute a job on the event-dispatching thread; creating this applet's GUI.
        inputGui frame =  new inputGui();//just here to get a clearer error
        try {
            SwingUtilities.invokeAndWait(new Runnable() {
                public void run() {
                    Container content = getContentPane();
                    inputGui frame =  new inputGui();//init GUI
                    content.add(frame.getRootNode() );//add rootNode to JFRame

                }
            });
        } catch (Exception e) {
            System.err.println("createGUI didn't complete successfully");
        }
    }

}

I just cant figure out why adding components suddenly creates a null pointer!. 我只是想不通为什么添加组件会突然创建一个空指针! If its any help my elements are nested like this: 如果有任何帮助我的元素嵌套如下:

在此输入图像描述

Code from inputGui.java inputGui.java中的代码

private void createUIComponents() {
   // TODO: place custom component creation code here
}

You selected option "Custom Create" on some component in UI designer. 您在UI设计器中的某个组件上选择了“自定义创建”选项。 You should create that component by yourself, otherwise it will fail. 您应该自己创建该组件,否则它将失败。 Uncheck that option and everything should be fine. 取消选中该选项,一切都应该没问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM