Tag: exception

附加zip存档调试

所以我有兴趣将文件附加到zip存档,我遇到了一些之前问过这个问题的用户,而另一个用户给出了这段代码片段作为该问题的解决方案: public static void updateZip(File source, File[] files, String path){ try{ File tmpZip = File.createTempFile(source.getName(), null); tmpZip.delete(); if(!source.renameTo(tmpZip)){ throw new Exception(“Could not make temp file (” + source.getName() + “)”); } byte[] buffer = new byte[4096]; ZipInputStream zin = new ZipInputStream(new FileInputStream(tmpZip)); ZipOutputStream out = new ZipOutputStream(new FileOutputStream(source)); for(int i = 0; i -1; read […]

ibatis spring java.lang.NoSuchMethodError com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser.parse

我在weblogic 10.3.6中使用spring 3.2.0和ibatis 2.3.4,同时在weblogic中部署。 我得到这个NoSuchMethodError如下: User defined listener org.springframework.web.context.ContextLoaderListener failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘gatewayService’ defined in ServletContext resource [/WEB-INF/applicationContext-granite-webservice.xml]: Cannot resolve reference to bean ‘daoIPInventory’ while setting bean property ‘dao’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘daoIPInventory’ defined in ServletContext resource [/WEB-INF/applicationContext-ip-ibatis-db.xml]: Cannot resolve reference to bean ‘sqlMapClient’ while […]

虽然我实现了’Serializable’,但为什么我得到NotSerializableExceptionexception

我在类’userInfo’中实现了Serializable。 我仍然有例外。 这是输出控制台 – java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: chatservernazmus.User at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1333) at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351) at java.util.ArrayList.readObject(ArrayList.java:593) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:974) at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1849) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329) at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1947) at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1871) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329) at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351) at chatservernazmus.Server.getAllUser(Server.java:74) at chatservernazmus.Server.(Server.java:44) at chatservernazmus.Main.main(Main.java:11) 这是我的两个class级: public class userInfo implements Serializable{ public […]

关闭system.in后的NoSuchElementException

[ 中断线程等待用户输入然后退出应用程序 ] 我想做与上面链接中提到的相同的练习。 但是,当我在成功关闭BufferedReader object之后尝试使用inConsole.nextLine()时,我遇到了NoSuchElementException ,尽管重新分配inConsole = new Scanner(System.in)以从标准输入中读取。 关闭BufferedReader object ,我不能像上面那样重新分配给Scanner对象并使用它吗?

如何在InputMismatchException之后重试输入?

我正在创建一个从用户获取输入的程序。如果用户输入无效命令,我想重新运行输入选项。 像这里只有整数输入是首选,但如果用户输入文本,那么我想捕获exception并重新运行该方法。 我试过这个但是它把我变成了一个无限循环。这是实现这个目标的最好方法。 如果有人帮助我这件事会很棒。 boolean retry = true; while(retry){ try{ //considering response from the user System.out.print(“\nEnter Your Command : “); f_continue = processresponse(scanner.nextInt()); retry = false; }catch(InputMismatchException e){ System.err.println(“\nPlease Input a Valid Command from 1-5 or 0 for Exit”); } }

显示SQL错误消息

我在我的java项目中使用JDBC连接到MySQL。 我在mySQL表中实现了一些检查约束。 我有一个表单,用户输入一些值并将其提交到MySQL表。 如果违反约束,Java会给出SQLException。 我的目的是显示一个弹出消息,告知我的表中违反了哪些条件。 如何在java中检索此信息? 我尝试了一个记录器,但它只在控制台中显示一条冗长的错误消息。

Integer.parse(String str)java.lang.NumberFormatException:错误

我不断得到数字格式的期望,即使我正在修剪字符串并且它们不包含非数字字符,奇怪的是它适用于某些数字,而不适用于其他数字。 下面是一个我得到数字格式exception的字符串示例。 此外,任何以0开头的字符串,例如“0208405223”,返回208405223,不再有零是应该发生的吗? String n=”3020857508″; Integer a = Integer.parseInt(n.trim()); System.out.println(a); 这是例外: Exception in thread “main” java.lang.NumberFormatException: For input string: “3020857508” at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.lang.Integer.parseInt(Integer.java:583) at java.lang.Integer.parseInt(Integer.java:615) at JavaBeans.Main.main(Main.java:15)

Java的。 可能抛出的params(NullpointerException)的函数?

当我有许多可以抛出exception的表达式时,例如: instanceObj.final_doc_type = instance.getFinalDocument().getValue().getType().getValue(); instanceObj.final_doc_date = instance.getFinalDocument().getValue().getDate().toGregorianCalendar().getTime(); instanceObj.appeal_date = instance.getFinalDocument().getValue().getAppealDate().getValue().toGregorianCalendar().getTime(); … instanceObj.start_doc_type = instance.getStartDocument().getValue().getDocType().getValue(); instanceObj.apeealed_type = instance.getStartDocument().getValue().getApeealedType().getValue(); instanceObj.declarers_list_mult_id = instance.getStartDocument().getValue().getDeclarers().getValue().getString(); … 是否有任何方法来处理这些表达式由某个函数将返回一些默认值(或null)如果参数无效并引发exception – 这可能发生,例如: instance.getFinalDocument().getValue().getDate() = null 因此,我不需要使用try-catch块包围每个表达式或检查每个点是否为null。

既不是BindingResult也不是普通的目标对象……例外

是的,我读到这是很常见的问题,但阅读这些post并没有真正帮助我。 简短的故事是我想在showAllComments.jsp上提交一份表格 COMMENT 这是控制器: @Controller @SessionAttributes public class CommentController { @Autowired private CommentService commentService; @RequestMapping(value = “/postNewComment”, method = RequestMethod.POST) public ModelAndView showAllUsers(@ModelAttribute(“command”) Comment comment, BindingResult result) { System.out.println(comment.getComment()); Map model = new HashMap(); model.put(“COMMENTS”, commentService.getComments()); return new ModelAndView(“showAllComments”, model); } } 结果如下: java.lang.IllegalStateException:BindingResult和bean名称’command’的普通目标对象都不能作为请求属性使用 但是,您可能需要从头开始查看整个故事 :用户通过单击启动index.jsp上的应用程序 Log in 该链接将他带到LoginController @RequestMapping(“/toLoginPage”) public ModelAndView goToLoginPage() { return […]

如何使用文本文件中的PrinterWriter类实现以下结果?

我的应用程序在此处提示用户输入包含的文本文件mixed.txt 12.2 Andrew 22 Simon Sophie 33.33 10 Fred 21.21 Hank Candice 12.2222 接下来,应用程序是PrintWrite到所有文本文件,即result.txt和errorlog.txt 。 mixed.txt中的每一行都应以数字开头,后跟名称。 但是,某些行可能包含另一种方式来表示名称,然后是数字。 以数字开头的那些应加到sum变量并写入result.txt文件,而那些以名称开头的行和数字应写入errorlog.txt文件。 因此,在MS-DOS控制台上的结果如下: 输入result.txt 总计:65.41 输入errorlog.txt 第3行出错 – 索菲33.33 第6行出错 – Candice 12.2222 好的,这是我的问题。 我只是设法进入舞台,我已将所有数字添加到result.txt和errorlog.txt文件的名称,我不知道如何继续从那里开始。 那么你们能给我一些建议或帮助我们如何实现我需要的结果吗? 以下是我的代码: import java.util.*; import java.io.*; class FileReadingExercise3 { public static void main(String[] args) throws FileNotFoundException { Scanner userInput = new Scanner(System.in); Scanner fileInput […]