Bla*_*aiz 3 java variables try-catch
String selectedDate = "2012-" + createdMonth
+ "-" + createdDay;
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd");
try {
Date createdDate = dateFormat.parse(selectedDate);
} catch (ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
int x = JOptionPane.showOptionDialog(frame,
"Here is your new booking schedule:\n "
+ "Timeslot: "
+ selectedTimeslot + "\n"
+ "Date: " + createdDate + "\n"
+ "Continue?",
"Booking Confirmation",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE, null,
options, options[1]);
Run Code Online (Sandbox Code Playgroud)
问题是JOptionPane中的createdDate无法解析为变量.这是为什么?我已经尝试过所有的东西,比如在try catch之外初始化Date对象,但它仍然不起作用.救命!