ParseException Java -
i writing appointment program allows user input appointment dates, description, , type of appointment. works correctly until make selection "print range" prints range of dates, when choose tells them enter start date , end date, program pulls of appointments between dates , displays them output box.
here errors getting print range :
appointmentnew.java:68: unreported exception java.text.parseexception; must caught or declared thrown date lowdate = sdf.parse(stdin.nextline()); ^ appointmentnew.java:70: unreported exception java.text.parseexception; must caught or declared thrown date highdate = sdf.parse(stdin.nextline()); ^ appointmentnew.java:77: unreported exception java.text.parseexception; must caught or declared thrown date newcurrentdate = sdf.parse(currentdate);
i think should try/catch block not real sure of how that, , wondering if provide me answer or example fix these errors.
here of code believe parse error taking place :
import java.util.*; import java.text.simpledateformat; import java.util.date; public class appointmentnew { public static void main (string[] args) throws exception { if (choicenum == 2) { system.out.print("\n\n\tenter start date in mm/dd/yyyy format: "); simpledateformat sdf = new simpledateformat("mm/dd/yyyy"); date lowdate = sdf.parse(stdin.nextline()); system.out.print("\n\n\tenter end date in mm/dd/yyyy format: "); date highdate = sdf.parse(stdin.nextline()); for(int = 0; < list.size(); i++) { int datespot = list.get(i).indexof(" "); string currentdate = list.get(i); currentdate.substring(0, datespot); date newcurrentdate = sdf.parse(currentdate); if (newcurrentdate.compareto(lowdate) >= 0 && newcurrentdate.compareto(highdate) <= 0) { system.out.println("\n\t" + list.get(i)); } } }
parse exception checked exception must have handle it. either throws or try catch block.
public static void main (string[] args)
should
public static void main (string[] args) throws parseexception
or in try catch block
try { //all parse operations } catch (parseexception e) { //handle exception here, of time log it. e.printstacktrace(); }
Comments
Post a Comment