皆様にご迷惑をおかけして申し訳ありませんが、今、私はこれに関して問題を抱えています。このコードは、それが java.lang.nullpointerexception であることを示しており、私はこれにほぼ 2 時間取り組んできました。以下のコードでエラーが発生します。
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);
}
同じ jbutton には、mysql データベースの別の部分に挿入するコードもあります。コードを上にコメントし、下のコードをそのままにしておくと、機能します。これが本当のヘッドスクラッチャーです。そのコードを以下に残しました
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:
誰かがそれを指摘できれば、それは素晴らしいことです。そうそう、画像は一般的なインターフェースインターフェースの下にあります
取り出すとこんな感じ
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());
結果はこれで、私のcatchステートメントではキャッチされません。宣言が try ステートメント内にない場合、以下のスタック トレースは表示されません。出力メニューにスタック トレースがない
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)