【发布时间】:2017-01-17 15:11:59
【问题描述】:
下面是我的代码,我正在尝试检查 xCoord 是否为空或为空,因此我可以抛出异常。我该怎么做? 我尝试使用 try/catch if xCoord == null 但这不起作用。
String x = JOptionPane.showInputDialog("X Coordinate", "Enter an x coordinate");
int xCoord = Integer.parseInt(x);
String y = JOptionPane.showInputDialog("Y Coordinate", "Enter a y coordinate");
int yCoord = Integer.parseInt(y);
String width = JOptionPane.showInputDialog("Radius", "Enter the length of the radius");
int radius = Integer.parseInt(width);
【问题讨论】:
-
只有
Objects可以为空 -
int永远不能为空,请改用Integer或检查x == null等。
标签: java if-statement exception null