0

我想抛出一个异常,以下是我的异常:

[致命错误] Test.xml:18:23: 元素类型 "value" 必须以匹配的 end-tag 终止</value>

现在我想单独取值 18 。

我尝试使用以下代码:

System.out.println(java.util.Arrays.toString(e.getMessage().split(":")));

但它正在打印:

[The element type "value" must be terminated by the matching end-tag "</value>".].

我怎样才能单独取值 18?

当我尝试使用以下代码时:

System.out.println(e.getMessage().toString());, 只是打印"The element type "value" must be terminated by the matching end-tag "</value>"."

4

2 回答 2

1

如果您只想打印 的值18,那么类似的方法可能会有所帮助:

String str = "[Fatal Error] Test.xml:18:23: The element type \"value\" must be terminated by the matching end-tag ";
System.out.println(str.split(":")[1]);

产量:18

编辑:第二个想法,e.getMessage()不会给你这样的字符串:[Fatal Error] Test.xml:18:23: The element type "value" must be terminated by the matching end-tag </value>. 该字符串似乎是某些日志记录工具的产物,因此您必须从文件或类似文件中读取它才能获得18显示的值。

于 2012-09-20T05:17:19.150 回答
0

尝试:

e.getMessage().split(":")[1]
于 2012-09-20T05:16:26.350 回答