the error...

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
        at javaapplication1.memberTable.AddMember(memberTable.java:21)
        at javaapplication1.GUI3.memberAddActionPerformed(GUI3.java:2345)
        at javaapplication1.GUI3.access$000(GUI3.java:28)
        at javaapplication1.GUI3$1.actionPerformed(GUI3.java:352)
        at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
        at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
        at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
        at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
        at java.awt.Component.processMouseEvent(Component.java:6041)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
        at java.awt.Component.processEvent(Component.java:5806)
        at java.awt.Container.processEvent(Container.java:2058)
        at java.awt.Component.dispatchEventImpl(Component.java:4413)
        at java.awt.Container.dispatchEventImpl(Container.java:2116)
        at java.awt.Component.dispatchEvent(Component.java:4243)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
        at java.awt.Container.dispatchEventImpl(Container.java:2102)
        at java.awt.Window.dispatchEventImpl(Window.java:2440)
        at java.awt.Component.dispatchEvent(Component.java:4243)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
        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)

where the problem can be found...

package javaapplication1;

import java.sql.Connection;

import java.sql.PreparedStatement;

import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

public class memberTable{
    private Connection con;
    PreparedStatement pstmt;
    DBConnection db = new DBConnection();
    public void AddMember(int mIDNum, String mFName, String mMidInit, String mLName, String mConNum,String mAddress, int mAge, String mGender ){
     try{
         db.connect();
      String sql = "insert into member(idnum, firstname, middleinitial, lastname, contactnumber, address, age, gender) values(?, ?, ?, ?, ?, ?, ?, ?);";
      
      
      /*this is where the error points at*/pstmt = con.prepareStatement(sql);
      pstmt.setInt(1,mIDNum);
      pstmt.setString(2,mFName);
      pstmt.setString(3,mMidInit);
      pstmt.setString(4,mLName);
      pstmt.setString(5,mConNum);
      pstmt.setString(6,mAddress);
      pstmt.setInt(7,mAge);
      pstmt.setString(8,mGender);


      db.disconnect();
   }catch( SQLException ex)
   {
       Logger.getLogger(GUI3.class.getName()).log(Level.SEVERE, null, ex);
   }
}
}

help me please... i do not see what the problem is because i think the codes are correct...

con isn't initialised.

con isn't initialised.

how do i instantiate it? isn't private Connection con; instantiating it?

Your declaration creates a reference variable that can hold a reference to an Object of type Copnnection. Its initial value is null. You still need to give it a real value by calling whatever SQL method returns you a new Connection and assigning that value to con.

so, how do i do that?

In pure Java you would use DriverManager.getConnection(...), but I don't recognise the DBConnection class that you're using, so I'm not able to comment on that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.