-1

好吧,所以在实现了这个org.apache.commons.lang3.text.WordUtils类之后,我希望能够使用这个WordUtils.wrap(String str, int width)函数。但我遇到了减速带。

我能够毫无问题地编译这个程序(我应该提到的是一个小程序)。我只需要设置一个 CLASSPATH 环境变量来引用 apache jar 文件,然后通过 appletviewer 让程序运行。但是,当我到达使用该WordUtils.wrap()函数的代码部分时,一切都变糟了,我在命令提示符下收到大约 20 行运行时错误。

错误:

Caught a SecurityException reading the system property 'awt.toolkit'; the System
Utils property value will default to null.
Caught a SecurityException reading the system property 'file.encoding'; the Syst
emUtils property value will default to null.
Caught a SecurityException reading the system property 'java.awt.fonts'; the Sys
temUtils property value will default to null.
Caught a SecurityException reading the system property 'java.awt.graphicsenv'; t
he SystemUtils property value will default to null.
Caught a SecurityException reading the system property 'java.awt.headless'; the
SystemUtils property value will default to null.
Caught a SecurityException reading the system property 'java.awt.printerjob'; th
e SystemUtils property value will default to null.
Caught a SecurityException reading the system property 'java.class.path'; the Sy
stemUtils property value will default to null.
Caught a SecurityException reading the system property 'java.compiler'; the Syst
emUtils property value will default to null.
Caught a SecurityException reading the system property 'java.endorsed.dirs'; the
 SystemUtils property value will default to null.
Caught a SecurityException reading the system property 'java.ext.dirs'; the Syst
emUtils property value will default to null.
Caught a SecurityException reading the system property 'java.home'; the SystemUt
ils property value will default to null.
Caught a SecurityException reading the system property 'java.io.tmpdir'; the Sys
temUtils property value will default to null.
Caught a SecurityException reading the system property 'java.library.path'; the
SystemUtils property value will default to null.
Caught a SecurityException reading the system property 'java.runtime.name'; the
SystemUtils property value will default to null.
Caught a SecurityException reading the system property 'java.runtime.version'; t
he SystemUtils property value will default to null.
Caught a SecurityException reading the system property 'java.util.prefs.Preferen
cesFactory'; the SystemUtils property value will default to null.
Caught a SecurityException reading the system property 'java.vm.info'; the Syste
mUtils property value will default to null.
Caught a SecurityException reading the system property 'user.country'; the Syste
mUtils property value will default to null.
Caught a SecurityException reading the system property 'user.region'; the System
Utils property value will default to null.
Caught a SecurityException reading the system property 'user.dir'; the SystemUti
ls property value will default to null.
Caught a SecurityException reading the system property 'user.home'; the SystemUt
ils property value will default to null.
Caught a SecurityException reading the system property 'user.language'; the Syst
emUtils property value will default to null.
Caught a SecurityException reading the system property 'user.name'; the SystemUt
ils property value will default to null.
Caught a SecurityException reading the system property 'user.timezone'; the Syst
emUtils property value will default to null.

这是导致所有这些麻烦的代码行:

String strWrap = WordUtils.wrap("A really really really really really long sentence.", 50);

这里发生了什么事?

4

2 回答 2

2

如何将行分隔符作为参数传递以绕过 SystemUtils 访问:

String strWrap = WordUtils.wrap("A really really really really really long sentence.", 50, "\n", false);
于 2012-09-26T23:02:59.240 回答
1

您的代码使用调用SystemUtils的WordUtils来查找系统使用的行分隔符:

newLineStr = SystemUtils.LINE_SEPARATOR;

由于浏览器的安全限制,SystemUtils 正在尝试读取可能不允许小程序读取的系统属性。

SystemUtils的文档说:

如果由于安全限制无法读取系统属性,则将此类中的相应字段设置为null并写入消息System.err

于 2012-09-26T22:41:15.030 回答