0

I am trying to create a JFormatted Text field, but when I try to add it, NullPointerException gets thrown at me. I checked if the stuff is in correct order or if something isn't null, but it doesn't seem so. I might be wrong though.

here is the block of code

public static void showTopic(String path) throws IOException{
    path = "topics/"+path+".txt";
    System.out.println(path);
    String[] topicFile = Login.readFile(path);
    int b =  Login.readLines(path);

    Topic.main(null);
    JFormattedTextField formattedTextField = new JFormattedTextField();
    formattedTextField.setEditable(false);
    formattedTextField.setBounds(50, 50, 100, 100);


    for (int i=0;i<b;i++)
        formattedTextField.setText(topicFile[i]);

    Topic.Contentframe.getContentPane().add(formattedTextField);


}

and the window frame

import java.awt.EventQueue;


public class Topic {

    static JFrame Contentframe;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    Topic window = new Topic();
                    window.Contentframe.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the application.
     */
    public Topic() {
        initialize();
    }

    /**
     * Initialize the contents of the frame.
     */
    private void initialize() {
        Contentframe = new JFrame();
        Contentframe.setBounds(100, 100, 550, 539);
        Contentframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Contentframe.getContentPane().setLayout(null);

        JButton btnNewButton = new JButton("New button");
        btnNewButton.setBounds(435, 0, 89, 23);
        Contentframe.getContentPane().add(btnNewButton);

    }

}

Thanks in advance :)

0 Answers0