Exception in thread "AWT-EventQueue-

I got this error and i believe it is because the variable for the ClockPanel is not in the nitComponents. The problem i have is i am using NetBeans ans can't get it in there. Can someone help me with this?

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
        at my.reminder.ClockPanel.initComponents(ClockPanel.java:41)
        at my.reminder.ClockPanel.<init>(ClockPanel.java:31)
        at my.reminder.NewGuiPanel.<init>(NewGuiPanel.java:35)
        at my.reminder.NewGuiPanel$10.run(NewGuiPanel.java:334)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
Drop_of_RainAsked:
Who is Participating?
 
objectsCommented:
The error would be caused by  dateTimeDisplayPanel being null.
Make sure you create it before u use it
0
 
objectsCommented:
you're referencing a null object, whats line 41
0
 
Drop_of_RainAuthor Commented:
I don't think these are being init, how do i get them into the init section of the code or what else needs to be done? What do i have to add to the GuiPanel to get the clock and date panel classes passed to it.


public class NewGuiPanel extends javax.swing.JFrame {
enum Mode {
CLOCK, ALARM, TIMER, DATE, AUDIO, REMINDERS, CUSTOM, SETUP
};

   private java.util.List<Mode> modes;
   private int modeIndex;
   private Mode currentMode;
   boolean alarmStarted = false;
   public String alarmTime;
   private javax.swing.JLabel timeDisplay;
   private ClockPanel clockPanel = new ClockPanel();
   private DatePanel datePanel = new DatePanel();
   
   /** Creates new form GuiPanel */
public NewGuiPanel() {
initComponents();

//initModes();
}
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Drop_of_RainAuthor Commented:
timeDisplayPanel = new javax.swing.JPanel(); This panel is in the GuiPanel  dateTimeDisplayPanel
Whar do we do about that, we need to get a reference of it or what?

dateTimeDisplayPanel.add(timeDisplayPanel);
0
 
objectsCommented:
not timeDisplayPanel, *dateTimeDisplayPanel* is not getting created.
0
 
Drop_of_RainAuthor Commented:
You know that 2 classes are being called into the GuiPanel class. In order for this to happen what needs to be done with code to all of the classes. Just tell me by showing me examples. In another profram i saw that called another panel into it, it called the contentPane into it like this:

        clockPanel = new ClockPanel();
        getContentPane().add(clockPanel, "Center");

Here is the code from the GuiPanel relating to dateTimeDisplayPanel


        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(dateTimeDisplayPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 459, Short.MAX_VALUE)
                    .addComponent(PanelNamePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(modeDisplay, javax.swing.GroupLayout.DEFAULT_SIZE, 459, Short.MAX_VALUE)
                    .addComponent(buttonPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(PanelNamePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(dateTimeDisplayPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(modeDisplay, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(buttonPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
0
 
Drop_of_RainAuthor Commented:
I can't created that same panel twice, once for the ClockPanel class and once for the Datepanel class because that is what you are telling me to do. The error haven't gotten to the DatePanel class yet and the same thing is going to happen.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.