簡単なATMのシステムを作ろうとしています。
Exception in Application start method
java.lang.reflect.InvocationTargetException
以下略
caused by: java.lang.RuntimeException: Exception in Application start method
以下略
Caused by: java.lang.NumberFormatException: For input string: "金額を入力:"
以下略
コンパイルし、実行すると上のように表示されます。どのように対処すればよいか教えていただきたいです。
java
1import java.net.Socket; 2import java.io.InputStream; 3import java.io.DataInputStream; 4import java.io.OutputStream; 5import java.io.DataOutputStream; 6import java.io.IOException; 7import java.net.UnknownHostException; 8 9import javafx.application.Application; 10import javafx.scene.Scene; 11import javafx.scene.control.*; 12import javafx.scene.layout.*; 13import javafx.stage.Stage; 14import javafx.geometry.Pos; 15import javafx.event.ActionEvent; 16import javafx.event.EventHandler; 17import java.util.*; 18 19public class ATMClient extends Application { 20 public static void main(String args[]) { 21 launch(); 22 } 23 24 public void start(Stage stage) { 25 List<String> list = getParameters().getRaw(); 26 final int PORT = 5432; 27 int money, deposit, withdraw, bal; 28 29 stage.setTitle("ATM"); 30 HBox subPane = new HBox(10); 31 subPane.setAlignment(Pos.CENTER); 32 VBox root = new VBox(10); 33 34 TextField tf = new TextField("金額を入力:"); 35 tf.setPrefSize(400,30); 36 TextArea ta = new TextArea(); 37 ta.setPrefSize(400,300); 38 39 Button b1 = new Button("入金"); 40 Button b2 = new Button("出金"); 41 b1.setPrefSize(50,30); 42 b2.setPrefSize(50,30); 43 subPane.getChildren().addAll(b1,b2); 44 root.getChildren().addAll(tf,ta,subPane); 45 46 Scene scene = new Scene(root); 47 stage.setScene(scene); 48 stage.show(); 49 50 money = Integer.parseInt(tf.getText()); 51 deposit = money; 52 withdraw = money; 53 54 b1.setOnAction(new EventHandler<ActionEvent>() { 55 public void handle(ActionEvent event) { 56 ta.appendText("入金:" + deposit + "円\n"); 57 tf.setText(""); 58 } 59 }); 60 61 b2.setOnAction(new EventHandler<ActionEvent>() { 62 public void handle(ActionEvent event) { 63 ta.appendText("出金:" + withdraw + "円\n"); 64 tf.setText(""); 65 } 66 }); 67 try(Socket s = new Socket(list.get(0),PORT); 68 OutputStream out = s.getOutputStream(); 69 DataOutputStream dos = new DataOutputStream(out); 70 InputStream in = s.getInputStream(); 71 DataInputStream dis = new DataInputStream(in)) { 72 73 dos.writeInt(deposit); 74 dos.writeInt(withdraw); 75 bal = dis.readInt(); 76 if (bal < 0) { 77 ta.appendText("残高不足:" + (-bal) + "円\n"); 78 } 79 } catch (UnknownHostException e) { 80 System.err.println("HOST'" + list.get(0) + "'is unknown"); 81 } catch (IOException e) { 82 e.printStackTrace(); 83 } 84 } 85}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/07/29 04:21
2020/07/29 08:05
2020/08/02 05:33