Please help, my Prog is compiling fine but when run it give me

Exception in thread "main" java.lang.NullPointerException

with the following:
1) at PatientReg.displaySQLErrors(PatientReg.java:424)

private void displaySQLErrors(SQLException e) {
    errorText.append("SQLException: " + e.getMessage() + "\n");
    errorText.append("SQLState:     " + e.getSQLState() + "\n");
    errorText.append("VendorError:  " + e.getErrorCode() + "\n");
  }

2) at PatientReg.loadAccounts(PatientReg.java:69) the line in bold

private void loadAccounts() {
    Vector v = new Vector();
    try {
      rs = statement.executeQuery("SELECT * FROM PatientTable");

      while (rs.next()) {
        v.addElement(rs.getString("patienNo"));
      }
    } catch (SQLException e) {
   [B]   displaySQLErrors(e);[/B]
    }
   PatientNumberList.setListData(v);
  }

3) at PatientReg.buildGUI(PatientReg.java:79)

loadAccounts();

called within the buildGUI() method
4) at PatientReg.main(PatientReg.java:441) the line in bold

public static void main(String[] args) {
    PatientReg patient = new PatientReg();

    patient.addWindowListener(new WindowAdapter() {
            @Override
      public void windowClosing(WindowEvent e) {
        System.exit(0);
      }
    });

    patient.init();
    [B]patient.buildGUI();[/B]
  }
}

Thanks in advance for your help and if you happen to need the whole project I'll be glad to provide.

From what I can guess your resultset might have returned null. Why dont you check while ((rs != null) && (rs.next())) at at PatientReg.loadAccounts(PatientReg.java:69) then check if your errorText itself is initialized properly.

yea sounds like you are at no data.
this below isn't by chance suppose to be "patientNo" ?

v.addElement(rs.getString("patienNo"));

yea sounds like you are at no data.
this below isn't by chance suppose to be "patientNo" ?

v.addElement(rs.getString("patienNo"));

hey :icon_smile:Thanks man I did that, thing are cool now but it still gives me these exceptions
1) when I press the Get PatientInfo, the last, the first, the next, the previous and goto buttons all give me this

SQLException: Result set type is TYPE_FORWARD_ONLY
SQLState: null 
VendorError: 0

2) when I press the insert button

SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement.
SQLState:     37000
VendorError:  -3502

here is the method that contain the statement, I see nothing wrong with it

public void actionPerformed(ActionEvent e) {
        try {
          Statement statement = connection.createStatement();
          int i = statement
              .executeUpdate("INSERT INTO PatientTable VALUES("
                  + jtfPnum.getText() + ", " + "'"
                  + jtfFname.getText() + "', " + "'"
                  + jtfSname.getText() + "', " + "'"
                  + jtfLocation.getText() + "',"+"'"
                  + jtfDOB.getText() + "'," + "'"
                  + jtfDOR.getText() + "'," + "'"
                  + jtfRace.getText() + "',"+"'"
                  + jtfGender.getText()+"',"+"'"
                  + jtfStat.getText() + "',"+ "'"
                  + jtfInit.getText() + "',"+"'"
                  + jtfID.getText()+ "',"+"'");
          errorText.append("Inserted " + i + " rows successfully");
          PatientNumberList.removeAll();
          loadAccounts();
        } catch (SQLException insertException) {
          displaySQLErrors(insertException);
        }
      }

3) when I press the delete button

SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.
SQLState:     07001

here is the method that contains the statement

public void actionPerformed(ActionEvent e) {
        try {
          Statement statement = connection.createStatement();
          int i = statement
              .executeUpdate("DELETE  FROM PatientTable WHERE patientNo = "
                  + PatientNumberList.getSelectedValue());
          errorText.append("Deleted " + i + " rows successfully");
          PatientNumberList.removeAll();
          loadAccounts();
        } catch (SQLException insertException) {
          displaySQLErrors(insertException);
        }
      }
    }

4)When I press the update button

SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in UPDATE statement.
SQLState:     37000
VendorError:  -3503

here is the method

public void actionPerformed(ActionEvent e) {
        try {
          Statement statement = connection.createStatement();
          int i = statement.executeUpdate("UPDATE PatientTable "
              + "SET patientNo='" + jtfPnum.getText() + "', "
              + "fname='" + jtfFname.getText() + "', "
              + "sname='" + jtfSname.getText() + "', " 
              + "location='" + jtfLocation.getText() + "',"
              + "dob='"+ jtfDOB.getText() + "',"
              + "dor='"+ jtfDOR.getText() + "'," 
              + "race='"+ jtfRace.getText() + "',"
              + "gender='"+ jtfGender.getText()+"',"
              + "status='"+ jtfStat.getText() + "',"
              + "initials='"+ jtfInit.getText() + "',"
              + "idnum='"+ jtfID.getText()+ "',"
              + "WHERE patientNo = " + PatientNumberList.getSelectedValue());
          errorText.append("Updated " + i + " rows successfully");
          PatientNumberList.removeAll();
          loadAccounts();
        } catch (SQLException insertException) {
          displaySQLErrors(insertException);
        }
      }
    }

Thank you very much in advance for your time. Hope you could help:icon_sad:

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.