0

例外をこぼしたいのですが、以下は私の例外です。

[致命的なエラー]Test.xml:18:23:要素タイプ "value"は、一致する終了タグで終了する必要があります</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

編集:2番目の考えでは、e.getMessage()この文字列のようなものは生成されません:[Fatal Error] Test.xml:18:23: The element type "value" must be terminated by the matching end-tag </value>。この文字列は、いくつかのログ機能の結果であるように思われるため、18showingの値を取得するには、ファイルなどから読み取る必要があります。

于 2012-09-20T05:17:19.150 に答える
0

試す:

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