Frage

Allright so after implementing the org.apache.commons.lang3.text.WordUtils class I was hoping to be able to use the WordUtils.wrap(String str, int width) function. But I reached a speed bump.

I was able to compile this program (which I should mention is an applet) without a single problem. I just had to set a CLASSPATH environment variable to reference the apache jar file, and then through appletviewer get the program to run. However when I reach the part of the code that uses the WordUtils.wrap() function everything turns sour and I get about 20 lines of runtime-errors on the command prompt.

Errors:

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.

Here is the line of code that causes all this trouble:

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

What's happening here?

War es hilfreich?

Lösung

How about passing the line separator as an argument to bypass the SystemUtils access:

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

Andere Tipps

Your code uses WordUtils which calls SystemUtils in order to find the line separator used by your system:

newLineStr = SystemUtils.LINE_SEPARATOR;

SystemUtils is trying to read system properties that an applet is probably not allowed to read, due to the security restrictions in a browser.

The documentation for SystemUtils says:

If a system property cannot be read due to security restrictions, the corresponding field in this class will be set to null and a message will be written to System.err

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top