此void函数测试QCManual结果表。到达时:
字符串日期=(字符串(qcModel.getValueAt(行,QCManualResultsTableModel.QCManualResult.RUNDATE_INDEX(
抛出错误
public static void checkManualResult(QCManualResultsTableModel qcModel, int row)
{
ArrayList<QcResultViolation> violations;
RuleEvaluator evaluator = null;
MultiMap<QcRules, QcSteps> ruleMap = new MultiMap<>();
if (qcModel.getRowCount() > 0)
{
//try {
Integer resultInstId = (Integer) qcModel.getValueAt(row, QCManualResultsTableModel.QCManualResult.INSTID_INDEX);
Integer qcLotId = (Integer) qcModel.getValueAt(row, QCManualResultsTableModel.QCManualResult.LOTID_INDEX);
Integer resultLevel = (Integer) qcModel.getValueAt(row, QCManualResultsTableModel.QCManualResult.LEVEL_INDEX);
Integer testNumber = (Integer) qcModel.getValueAt(row, QCManualResultsTableModel.QCManualResult.TESTNUM_INDEX);
Double result = (Double) qcModel.getValueAt(row, QCManualResultsTableModel.QCManualResult.RESULT_INDEX);
String date = (String) qcModel.getValueAt(row, QCManualResultsTableModel.QCManualResult.RUNDATE_INDEX);
evaluator = new RuleEvaluator(resultInstId);
ruleMap = getRules(resultInstId, resultLevel, qcLotId);
if (ruleMap.size() > 0 && result != null)
{
evaluator.SetRuleMap(ruleMap);
violations = evaluator.CheckResult(testNumber, resultLevel, qcLotId, resultInstId, new BigDecimal(result), date);
}
堆栈跟踪错误:
java.lang.ClassCastException: java.sql.Date cannot be cast to java.lang.String
at org.css.QCApproval.QCUtil.checkManualResult(QCUtil.java:88)
at org.css.QCTables.QCManualResultsTableModel.setValueAt(QCManualResultsTableModel.java:418)
at javax.swing.JTable.setValueAt(JTable.java:2741)
at org.jdesktop.swingx.JXTable.setValueAt(JXTable.java:1473)
at javax.swing.JTable.editingStopped(JTable.java:4723)
at javax.swing.AbstractCellEditor.fireEditingStopped(AbstractCellEditor.java:141)
at javax.swing.DefaultCellEditor$EditorDelegate.stopCellEditing(DefaultCellEditor.java:368)
at javax.swing.DefaultCellEditor.stopCellEditing(DefaultCellEditor.java:233)
at org.jdesktop.swingx.table.NumberEditorExt.stopCellEditing(NumberEditorExt.java:129)
at javax.swing.DefaultCellEditor$EditorDelegate.actionPerformed(DefaultCellEditor.java:385)
at javax.swing.JTextField.fireActionPerformed(JTextField.java:508)
at javax.swing.JTextField.postActionEvent(JTextField.java:721)
at javax.swing.JTextField$NotifyAction.actionPerformed(JTextField.java:836)
at javax.swing.JFormattedTextField$CommitAction.actionPerformed(JFormattedTextField.java:1124)
at javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1662)
at javax.swing.JComponent.processKeyBinding(JComponent.java:2879)
at javax.swing.JComponent.processKeyBindings(JComponent.java:2926)
at javax.swing.JComponent.processKeyEvent(JComponent.java:2842)
at java.awt.Component.processEvent(Component.java:6293)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4872)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4698)
at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1887)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:762)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:1027)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:899)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:727)
at java.awt.Component.dispatchEventImpl(Component.java:4742)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4698)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:747)
at java.awt.EventQueue.access$300(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:706)
at java.awt.EventQueue$3.run(EventQueue.java:704)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:720)
at java.awt.EventQueue$4.run(EventQueue.java:718)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:717)
at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:159)
[catch] at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
不能将字符串对象强制转换为日期-时间对象。这些类型是不相关的。
您可以要求日期-时间对象生成文本。
永远不要使用有严重缺陷的遗留日期时间类型,如java.sql.Date
。仅使用java.time类。
要从类似于SQL标准类型DATE
的列中检索值,请使用java.time.LocalDate
。
LocalDate ld = myResultSet.getObject( … , LocalDate.class ) ;
生成标准ISO 8601格式的文本:YYYY-MM-DD
。
String output = ld.toString() ;
要生成其他格式的文本,请使用DateTimeFormatter
和DateTimeFormatterBuilder
类。这些已经被广泛报道,所以搜索了解更多。