0

I am trying to make a very simple Time Manager, when i compile it shows an error. I am unable to find the mistake in my code which is producing the error.

JPanel otherPanel = new JPanel();
otherPanel.add(BorderLayout.WEST, timingsPanel);
otherPanel.add(BorderLayout.CENTER, todoPanel);
otherPanel.add(BorderLayout.EAST, checkPanel);

The error is:

Error message: Exception in thread "main" java.lang.NullPointerException
    at java.desktop/java.awt.Container.addImpl(Container.java:1117)
    at java.desktop/java.awt.Container.add(Container.java:460)
    at GUI.setUpGui(GUI.java:57) at manager.main(manager.java:6)

code around line 57:

//setting up otherstuff
otherPanel = new JPanel();
otherPanel.add(BorderLayout.WEST, timingsPanel);
otherPanel.add(BorderLayout.CENTER, todoPanel);
otherPanel.add(BorderLayout.EAST, checkPanel);

The below code in minimum, it's also showing the same error

import javax.swing.*;
import java.awt.*;

public class timeclass
{
    JFrame frame;
    JPanel headerPanel;
    JLabel header;
    JPanel otherPanel;
    JPanel timingsPanel;
    JPanel todoPanel;
    JPanel checkPanel;


    public void setUpGui()
    {
        frame = new JFrame("Time Manager");

        //setting up header
        headerPanel = new JPanel();
        header = new JLabel("Time Manager");
        header.setFont(new Font("Times New Roman", Font.BOLD, 36));
        headerPanel.add(header);

        //setting up otherstuff
        otherPanel = new JPanel();
        otherPanel.add(BorderLayout.WEST, timingsPanel);
        otherPanel.add(BorderLayout.CENTER, todoPanel);
        otherPanel.add(BorderLayout.EAST, checkPanel);

        //setting up frame
        frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
        BoxLayout boxLayout4 = new BoxLayout(frame, BoxLayout.Y_AXIS);
        frame.setLayout(boxLayout4);
        frame.add(headerPanel);
        frame.add(otherPanel);
        frame.setSize(900, 400);
        frame.setVisible(true);
    }
}
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
x blade
  • 120
  • 10

0 Answers0