![](/img/trans.png)
[英]Exception in thread “AWT-EventQueue-0” java.lang.NumberFormatException: empty
[英]Exception in thread “AWT-EventQueue-0” java.lang.NumberFormatException: empty String OS Kernel Simulation
我正在用GUI在Java中進行OS內核仿真的項目。 我創建了一個Jtable,用於添加流程(任務)。 現在,我嘗試使用FIFO(先進先出)算法執行進程。 我正在嘗試實現Button功能,以使用fifo算法執行進程。 按下按鈕后,在這里引發了以下異常。
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: empty String
我在以下功能中可能在這里做錯了
private void fifo_BtnActionPerformed(java.awt.event.ActionEvent evt) {
//DefaultTableModel model = (DefaultTableModel) processTable.getModel();
int totalNoOfProcess = p.totalProcess();
for (int i = 0; i < totalNoOfProcess; i++) {
Process cp = p.getPCB(i);
double burstTime = cp.getBurst_time();
while (burstTime > 0) {
burstTime = burstTime - cpuTime;
cp.setStatus("running");
DefaultTableModel newRow = new DefaultTableModel();
newRow.equals(model);
newRow.setValueAt(new Object[]{
(Double.parseDouble(processID_TF.getText())), processNameTF.getText(), Double.parseDouble(burstTimeTF.getText()), Double.parseDouble(priorityTF.getText()), statusTF.getText().trim()
},i, i);
//newRow.addRow(new Object[] {(Double.parseDouble(processID_TF.getText())), processNameTF.getText(), Double.parseDouble(burstTimeTF.getText()), Double.parseDouble(priorityTF.getText()), statusTF.getText().trim()});
model.removeRow(i);
//model.setValueAt(newRow, i, i);
for (int a = 0; a < 100; a++) {
model.fireTableDataChanged();
}
}
cp.setBurst_time(0);
cp.setStatus("Completed");
DefaultTableModel anotherRow = new DefaultTableModel();
anotherRow.equals(model);
anotherRow.addRow(new Object[] {
(Double.parseDouble(processID_TF.getText())), processNameTF.getText(), Double.parseDouble(burstTimeTF.getText()), Double.parseDouble(priorityTF.getText()), statusTF.getText().trim()
});
model.removeRow(i);
model.setValueAt(anotherRow, i, i);
model.fireTableDataChanged();
}
}
這是我的add_processes函數
private void add_processBtnActionPerformed(java.awt.event.ActionEvent evt)
{
p.createPCB((Double.parseDouble(processID_TF.getText())), processNameTF.getText(), Double.parseDouble(burstTimeTF.getText()), Double.parseDouble(priorityTF.getText()), statusTF.getText().trim());
Process process = p.getPCB(count);
process.setId(Double.parseDouble(processID_TF.getText()));
process.setName(processNameTF.getText().trim());
process.setBurst_time(Double.parseDouble(burstTimeTF.getText()));
process.setPriority(Double.parseDouble(priorityTF.getText()));
process.setStatus(statusTF.getText());
model.addRow(new Object[]{process.getId(), process.getName(), process.getBurst_time(), process.getPriority(), process.getStatus()});
//model.fireTableDataChanged();
processID_TF.setText("");
processNameTF.setText("");
burstTimeTF.setText("");
priorityTF.setText("");
count++;
}
這是按下fifo按鈕后引發的整個異常錯誤。 添加過程功能正常
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: empty String
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:992)
at java.lang.Double.parseDouble(Double.java:510)
at ahmed.riphah.OS.ProcessManagementGUI.fifo_BtnActionPerformed(ProcessManagementGUI.java:251)
at ahmed.riphah.OS.ProcessManagementGUI.access$100(ProcessManagementGUI.java:14)
at ahmed.riphah.OS.ProcessManagementGUI$2.actionPerformed(ProcessManagementGUI.java:96)
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:6297)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3275)
at java.awt.Component.processEvent(Component.java:6062)
at java.awt.Container.processEvent(Container.java:2039)
at java.awt.Component.dispatchEventImpl(Component.java:4660)
at java.awt.Container.dispatchEventImpl(Container.java:2097)
at java.awt.Component.dispatchEvent(Component.java:4488)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4575)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4236)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4166)
at java.awt.Container.dispatchEventImpl(Container.java:2083)
at java.awt.Window.dispatchEventImpl(Window.java:2489)
at java.awt.Component.dispatchEvent(Component.java:4488)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:668)
at java.awt.EventQueue.access$400(EventQueue.java:81)
at java.awt.EventQueue$2.run(EventQueue.java:627)
at java.awt.EventQueue$2.run(EventQueue.java:625)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
at java.awt.EventQueue$3.run(EventQueue.java:641)
at java.awt.EventQueue$3.run(EventQueue.java:639)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:638)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
當您單擊該按鈕時,GUI中的文本字段之一為空,從而導致:
Double.parseDouble( aTextField.getText() );
失敗(這是異常告訴您的內容)。
因此,有兩種情況:
例如:
if( processID_TF.getText().match("\\d+") ){
// proceed with normal behaviour
}else{
JOptionPane.showMessageDialog(null, "You must indicate a correct process ID.");
}
例如:
double value;
try{
value = Double.parseDouble(processID_TF.getText());
}catch(Exception e){
value = 0.; // Default value
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.