public static void ToaddBook() throws IOException
{
InputStreamReader iin = new InputStreamReader(System.in);
BufferedReader bin = new BufferedReader(iin);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
BookDao bookdao = new BookDao();
Book book = new Book();
Addstock addstock = new Addstock();
String bookname,booktype,author,dir,photo,sn,publish,temp;
Double bookprice,addstockprice;
Date timer;
Integer salestock,hot;
System.out.println("\n====== 添加书籍:====== \n");
temp = bin.readLine();
System.out.print("6.请输入出版日期(如:2008-01-01 的格式):");
timer = formatter.parse(bin.readLine());
book.setTimer(timer);
addstock.setAddstockPrice(addstockprice);
addstock.setAddstockDate(new java.util.Date());
addstock.setBook(book);
book.getStocks().add(addstock);
bookdao.addBook(book);
System.out.println("添加书籍成功!");
}红色部分出错,提示:Unhandled exception type ParseException
{
InputStreamReader iin = new InputStreamReader(System.in);
BufferedReader bin = new BufferedReader(iin);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
BookDao bookdao = new BookDao();
Book book = new Book();
Addstock addstock = new Addstock();
String bookname,booktype,author,dir,photo,sn,publish,temp;
Double bookprice,addstockprice;
Date timer;
Integer salestock,hot;
System.out.println("\n====== 添加书籍:====== \n");
temp = bin.readLine();
System.out.print("6.请输入出版日期(如:2008-01-01 的格式):");
timer = formatter.parse(bin.readLine());
book.setTimer(timer);
addstock.setAddstockPrice(addstockprice);
addstock.setAddstockDate(new java.util.Date());
addstock.setBook(book);
book.getStocks().add(addstock);
bookdao.addBook(book);
System.out.println("添加书籍成功!");
}红色部分出错,提示:Unhandled exception type ParseException
把ParseException加在方法签名中IOException后面,或者把红色那句用try...catch括起来。
把ParseException加在方法签名中IOException后面 怎么搞?
try{
你出现异常的代码
}catch(Exception e){e.printStackTrace()}