Tag: exception

Java正则表达式错误 – 没有组1

我在我的项目中将其作为UnitTest运行 public class RadioTest { private static Pattern tier; private static Pattern frequency; private static Pattern state; static { tier = Pattern.compile(“Tier: \\d”); frequency = Pattern.compile(“Frequency: \\d{3}”); state = Pattern.compile(“State: (OFF|ON)”); } @Test public void test() { String title = “Tier: 2”; String title2 = “Frequency: 135”; String title3 = “State: ON”; assertTrue(tier.matcher(title).matches()); assertTrue(frequency.matcher(title2).matches()); assertTrue(state.matcher(title3).matches()); […]

weblogic中的类强制转换exception

我有一个使用泽西jars的Web应用程序(WAR文件)。现在我正在尝试部署这个我得到类强制转换exception(一些bootstrap servlet使用泽西)..在分析中我发现weblogic本身有共同的泽西jar子\ modules..and我的网络应用程序有不同版本的泽西jar子。 现在,如果我删除common / modules jersey jar,那么我的web应用程序就已部署。我想知道如何让我的web应用程序使用自己版本的jersey jar,以便在不删除常用/模块jar的情况下部署它.PS我的.war文件没有weblogic.xml,weblogic正在动态生成它。

没有捕获SQLiteException

我正在尝试捕获“android.database.sqlite.SQLiteException:错误代码5:数据库被锁定”exception: try { db.insert(“mytable”, null, myvalues); } catch(SQLiteException e) { Log.d(“My App”, “caught”); … } 出于某种原因,我仍然得到错误,并且“抓住”没有出现在LogCat中。 我尝试捕获一般的“exception”,但仍然无效。 怎么了? 更新我发现了这个问题,这真的很奇怪:出于某种原因,将db.insert()更改为db.insertOrThrow(),因为goto10声明修改了所有内容。 错误来自该行,但也许它不是抛出exception而只是崩溃或什么?

在JSON中嵌套太深……我应该切换到XML吗?

我收到一个JSONException抱怨非常深的嵌套(超过30)。 我知道该值是在JSONWriter中硬编码的。 我该怎么办? 如果存在这样的事情,使用另一个没有这个限 切换到XML? 更新:我将标记的树结构序列化为JSON。 所以从root开始,每个节点都在嵌套它们的子节点,而这些节点又将它们嵌套… {“type”:”n1″,”links”:[{“label”:”l1″,”target”:{“type”:”n2″,”links”:[{“label”:”l2″,”target”:{ …}}]}}]} 我可能不得不重新考虑我序列化对象结构的方式。 更新 :我正在使用org.json

调用Scanner.close()会抛出nosuchelementexception

我有一个简单的方法,它将命令打印到屏幕,扫描用户的输入,并将其作为字符串返回。 如果用户的输入无效,它会通知用户并再次询问。 这个方法工作得很好,但我的讲师提到我们应该总是关闭资源,所以我回去并在close方法中添加,现在每次调用方法时都会收到NoSuchElementException,无论用户输入如何。 这是代码…… private String getUserString(String userCommand) { System.out.println(userCommand); Scanner scan = new Scanner(System.in); String userinput = scan.nextLine().trim(); if (userinput.isEmpty()){ System.out.println(“Invalid choice”); return getUserString(userCommand); } else { return userinput; } } exception总是指向userinput作为scan.nextLine()启动的行.trim()注意*我在每个return语句之前的每一行都添加了scan.close(),但是我没有在上面包含它。

如何在Java中修改对象时迭代对象?

可能重复: Java:在迭代集合时高效等效删除 在迭代它时从java中的集合中删除项目 我正在尝试遍历HashMap : Map group0 = new HashMap(); …并提取group0每个元素。 这是我的方法: // iterate through all Members in group 0 that have not been assigned yet for (Map.Entry entry : group0.entrySet()) { // determine where to assign ‘entry’ iEntryGroup = hasBeenAccusedByGroup(entry.getKey()); if (iEntryGroup == 1) { assign(entry.getKey(), entry.getValue(), 2); } else { assign(entry.getKey(), entry.getValue(), 1); […]

java.net.SocketException:网络无法访问:连接

我试图使用此方法从Web服务器下载xml文本文件: static void download (String url , String fileName) throws IOException{ FileWriter xmlWriter; xmlWriter = new FileWriter(fileName); System.out.println(“URL to download is : ” + url); // here Exception is thrown///////////////////////////////// BufferedReader inputTxtReader = new BufferedReader (new BufferedReader(new InputStreamReader(addURL.openStream()))); //////////////////////////////////////////////////////// String str ; String fileInStr = “”; str = inputTxtReader.readLine(); while (!(str == null) ){///&& !(str.equals(“”)) […]

测试失败时记录exception的最佳方法(例如使用junit规则)

当我运行一个完整的测试套件时,如果导致测试失败的exception会出现在我的(SLF4J-)日志中,将会很有帮助。 实现这一目标的最佳方法是什么? 我想要什么 是一个junit4规则,为我处理exception日志记录。 代码 @Rule public TestRule logException = new TestWatcher() { @Override public void failed(Description d) { catch (Exception e) { logger.error(“Test ({}) failed because of exception {}”, d, e); throw e; } } } 当然不起作用,因为我只能从try块中捕获exception。 是否有一种解决方法以某种方式以类似的简单和一般方式实现这一目标? 顺便说一下,我现在在做什么 在创建exception时记录exception。 但是在调用者和库之间的接口上记录exception会更好,所以在我的情况下在测试用例中。 在创建例外时不记录也可以保证在调用者决定记录它们时它们不会多次显示。

在Hadoop 2上运行作业时无法初始化集群exception

问题与我之前的问题相关联所有守护进程都在运行,jps显示: 6663 JobHistoryServer 7213 ResourceManager 9235 Jps 6289 DataNode 6200 NameNode 7420 NodeManager 但wordcount示例继续失败,出现以下exception: ERROR security.UserGroupInformation: PriviledgedActionException as:root (auth:SIMPLE) cause:java.io.IOException: Cannot initialize Cluster. Please check your configuration for mapreduce.framework.name and the correspond server addresses. Exception in thread “main” java.io.IOException: Cannot initialize Cluster. Please check your configuration for mapreduce.framework.name and the correspond server addresses. at org.apache.hadoop.mapreduce.Cluster.initialize(Cluster.java:120) […]

尝试使用pdfBox时出现.NoClassDefFoundError

当我尝试使用其中一个PDFBox示例来提取图像时,在运行时,它给出了以下exception: Exception in thread “main” java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory at org.apache.pdfbox.pdfparser.BaseParser.(BaseParser.java:68) at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:1218) at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:1186) at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:1111) at pdfboxtest.PdfBoxTest.extractImage(PdfBoxTest.java:69) at pdfboxtest.PdfBoxTest.main(PdfBoxTest.java:53) Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory at java.net.URLClassLoader$1.run(URLClassLoader.java:372) at java.net.URLClassLoader$1.run(URLClassLoader.java:361) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:360) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) … 6 more 这是发生exception的代码的一部分,在最后两行: String pdfFile = “pdf file path”; File pdf=new File(pdfFile); PDDocument document = null; […]