Sorry to bother everyone and all now I am having an issue in terms of this. This code says that it is a java.lang.nullpointerexception and I have been working on this for almost 2 hours now. the code below give the error.
try
{
increment = transnum+1;
String hmo = cbHMO.getSelectedItem().toString();
String testname = cbTests.getSelectedItem().toString();
int amount = Integer.parseInt(txtTestAmount.getText());
double discount = Double.parseDouble(txtDiscountAmount.getText());
double total = Double.parseDouble(txtTotal.getText());
double amountpaid = Double.parseDouble(txtPAMount.getText());
String refer = txtReferred.getText();
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/smartcare", "root", "");
stmt = conn.createStatement();
String sql = "INSERT INTO transactions (transnum, patientid, transtype, paymenttype, initialamount, discount, total, amountpaid, hmo, referral, time, date) values (?,?,?,?,?,?,?,?,?,?,?,?)";
PreparedStatement preparedStmt = conn.prepareStatement(sql);
preparedStmt.setInt(1, increment);
preparedStmt.setInt(2, pid);
preparedStmt.setString(3, testname);
preparedStmt.setString(4,ptype);
preparedStmt.setInt(5, amount);
preparedStmt.setDouble(6, discount);
preparedStmt.setDouble(7, total);
preparedStmt.setDouble(8,amountpaid);
preparedStmt.setString(9, hmo);
preparedStmt.setString(10, refer);
preparedStmt.setTime(11, time);
preparedStmt.setDate(12, daten);
preparedStmt.execute();
increment++;
JOptionPane.showMessageDialog(null, "Added Successfully");
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, e);
}
Now on the same jbutton a code also is there to insert into a different part of the mysql database and if I comment the code on top and just leave the one below it would work. this is the real head scratcher here folks. left the code of that below
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/smartcare", "root", "");
stmt = conn.createStatement();
PatientsList pl = new PatientsList();
pid = pl.getPID();
String fname = pl.getFname();
String lname = pl.getLname();
//DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
//DateFormat timeformat = new SimpleDateFormat("HH:MM:SS");
//Date dateobj = new Date();
// Calendar calobj = Calendar.getInstance();
// java.util.Date date = new java.util.Date();
java.sql.Time time = getCurrentJavaSqlTime();
java.sql.Date daten = getCurrentJavaSqlDate();
User u = new User();
int uid=u.getPID();
//JOptionPane.showMessageDialog(null, dateFormat.format(calobj.getTime()));
//JOptionPane.showMessageDialog(null, timeformat.format(calobj.getTime()));
wincrement = qnumber+1;
String sql2 = "INSERT INTO patientswait(queuenumber,patientid,firstname,lastname,time,date,status,userid, deptid) values (?,?,?,?,?,?,?,?,?)";
PreparedStatement preparedStmt = conn.prepareStatement(sql2);
preparedStmt.setInt(1, wincrement);
preparedStmt.setInt(2, pid);
preparedStmt.setString(3, fname);
preparedStmt.setString(4, lname);
preparedStmt.setTime(5, time);
preparedStmt.setDate(6, daten);
preparedStmt.setString(7, "not sent");
preparedStmt.setInt(8, uid);
preparedStmt.setInt(9, did);
preparedStmt.execute();
increment++;
//conn.close();
JOptionPane.showMessageDialog(null, "Added Successfully");
}// TODO add your handling code here:
catch (Exception ex) {
JOptionPane.showMessageDialog(null, ex);
} // TODO add your handling code here:
if anyone can point it out that would be fantastic. oh yeah image is below of the general interface interface
this is what appears when I take out
increment = transnum+1;
String hmo = cbHMO.getSelectedItem().toString();
String testname = cbTests.getSelectedItem().toString();
int amount = Integer.parseInt(txtTestAmount.getText());
double discount = Double.parseDouble(txtDiscountAmount.getText());
double total = Double.parseDouble(txtTotal.getText());
double amountpaid = Double.parseDouble(txtPAMount.getText());
and the result is this which it would not be caught by my catch statement. the stack trace below does not appear if the declarations are not inside the try statement. no stack trace on the output menu
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at smartcare.CashierCustomer.bSubmitMouseClicked(CashierCustomer.java:769)
at smartcare.CashierCustomer.access$600(CashierCustomer.java:28)
at smartcare.CashierCustomer$9.mouseClicked(CashierCustomer.java:331)
at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:270)
at java.awt.Component.processMouseEvent(Component.java:6538)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at java.awt.Component.processEvent(Component.java:6300)
at java.awt.Container.processEvent(Container.java:2236)
at java.awt.Component.dispatchEventImpl(Component.java:4891)
at java.awt.Container.dispatchEventImpl(Container.java:2294)
at java.awt.Component.dispatchEvent(Component.java:4713)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4534)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
at java.awt.Container.dispatchEventImpl(Container.java:2280)
at java.awt.Window.dispatchEventImpl(Window.java:2750)
at java.awt.Component.dispatchEvent(Component.java:4713)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)