有没有办法解决此异常?

This is the second time I am posting this question. Due to incorrectly phrasing my last attempt to this question, it was closed. I am using IntelliJ IDEA's swing GUI form to model my UI. Every component I add in my GUI form, it gets declared in the java file of that form (which i have shown below). The westPanel.add(patientList); line in the searchId method returns an Exception that I'd like to fix. Now I was told I should initialize westPanel, but I didn't have to initialize other components such as rootPanel or tabPane1, so how do I fix this problem.

Note: Replacing private JPanel westPanel; with private JPanel westPanel = new JPanel(); (Assuming this is how I initialize) doesn't give me exception but does not show my patientList (JList) in the form when I run main(). I am new to Java, so I badly need suggestions to fix this issue.

public class nextPage {
    private JTabbedPane Monitor;
    private JPanel rootPanel;
    private JPanel tabPane1;
    private JPanel tabPane2;
    private JPanel westPanel;
    private JRadioButton monitorBttn;
    private JPanel northEastPanel;
    private JPanel southEastPanel;
    private JTable monTable;
    private String arg;

    public nextPage(String identification){
        this.arg = identification;
        searchId(this.arg);
    }

    public void searchId(String id){
        /*
        This is a temporary method
         */
//        System.out.println(id);
        String[] names = {"Name1","Name2","Name3"};
        JList<String> patientList = new JList(names);
        westPanel.add(patientList);

    }


    public static void main(String[] args) {
        JFrame frame = new JFrame("Next Page");
        frame.setContentPane(new nextPage("800").rootPanel);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
    }
}
评论