-1

My JDialog throws a NullPointerException when I access it through Jframe but works fine when I run the JDialog class itself.

I have a jMenuItem called "modify" in my jFrame that accesses jDialog.

private void modifyActionPerformed(java.awt.event.ActionEvent evt){                                       

     Modify mod = new Modify(this,true); //"Modify" is my jDialog class name.
     mod.setVisible(true);

}            

Modify throws a NullPointerException when I query the database when I access the dialog from jframe but I can query the database successfully from Modify when I run the class itself.

mKorbel
  • 109,525
  • 20
  • 134
  • 319
CodeFreak
  • 31
  • 5
  • 1
    Something wrong in your code you haven't posted. – StanislavL Feb 25 '14 at 05:41
  • First rule of programming: read the error message. Post the complete stack trace and the relevant code. The stack trace tells you exactly where the exception happens, and in which context. – JB Nizet Feb 25 '14 at 06:52
  • @JBNizet I did. It keeps pointing to codes that worked when I ran the jDialog directly. – CodeFreak Feb 25 '14 at 07:30
  • So now you ask us for help, but since it didn't help you to read the message, you consider it's useless for us? So we have almost no code, don't know anything about the exception, but we're supposed to explain what's the reason for it and how to avoid it? We're not wizards. – JB Nizet Feb 25 '14 at 07:38
  • @JBNizet It points to stmt = conn.createStatement in the jDialog. Although it doesn't throw a NullPointerException when I run it directly. – CodeFreak Feb 25 '14 at 07:45
  • the something problem in your Query on connection – Benjamin Feb 25 '14 at 08:01

2 Answers2

0

please Check your code somthing else in your code .

check Modify Class.

This Simple example shows JDialog opening.

      import java.awt.*;
      import javax.swing.*;
      import java.util.*;
      import java.awt.event.*;
      class DiagonalLineDemo extends JFrame implements ActionListener {
      public DiagonalLineDemo()
    {
       setVisible(true);
       setSize(100,100); 
       JMenuBar s=new JMenuBar();
       JMenu m=new JMenu("Open ");
       JMenuItem s1=new JMenuItem("Dialog");
       m.add(s1);
       s.add(m);
       setJMenuBar(s);
       s1.addActionListener(this);
          }
     public void actionPerformed(ActionEvent e)
    {
        JDialog j=new JDialog(this,true);
   j.setVisible(true);
     }
        public static void main(String args[]) {
       DiagonalLineDemo f=new DiagonalLineDemo();

      }
    }

enter image description here

Open Frame click Menu open and MenuItem Dialog.

enter image description here

After Click Dialog The DialogBox is shows.

ravibagul91
  • 20,072
  • 5
  • 36
  • 59
Benjamin
  • 2,257
  • 1
  • 15
  • 24
  • No, no. The buttons work but it throws a NullPointerException when I query the database although it queries the DB successfully when I run the dialog directly. – CodeFreak Feb 25 '14 at 07:59
0

Fixed it. Turns out I just needed to set my jDialog database connection to non-static so I can initialize the class from my main interface. Thanks anyway.

CodeFreak
  • 31
  • 5