Sometimes you run into a test that works when run from within Eclipse but not from the command line. To debug the failing test from Eclipse, you can configure the Junit ant task to accept remote debugging sessions.
This can be done by adding the following lines to the junit task:
<!-- For remote debugging from Eclipse -->
<jvmarg value="-Xdebug" />
<jvmarg value="-Xnoagent" />
<jvmarg value="-Djava.compiler=NONE" />
This will make the task wait for an incoming debug connection on port 8787. It is necessary to have the fork attribute on the junit task set to true, because the jvmarg values can only be given to a starting Java virtual machine.
Casting the array obtained by invoking the toArray() method on a collection yields a ClassCastException.
String strings = listOfStrings.toArray();
will throw the ClassCastException.
The trick is to use the overloaded version of toArray(), which takes an array as parameter. This the javadoc description of the method
"Returns an array containing all of the elements in this list in the correct order; the runtime type of the returned array is that of the specified array."
The solution is therefore to do this:
String sv = (String)v.toArray(new String);
If you are having problems with non-ASCII characters (for example the Danish æ, ø and å) not showing up correctly in your Java application, try giving the Java VM the following argument:
You can verify that the charset has been set with this statement: