imagej / imagej2

Open scientific N-dimensional image processing :microscope: :sparkler:
https://imagej.net/
BSD 2-Clause "Simplified" License
1.17k stars 332 forks source link

Bug in String.format() #286

Closed quantixed closed 3 years ago

quantixed commented 3 years ago

A user on Stack Overflow reported that format was not a recognised String function in IJ 1.53c. Using IJ 1.53i or IJ 1.53j I get a different error.

s = String.format("%04d", 13);
print(s);

Gives:

Error:      java.util.IllegalFormatConversionException: d != java.lang.Double in line 1:

        var ; initializeSciJavaParameters ( ) ; s = String . format ( "%04d" , 13 <)> ; 

This is using (Fiji Is Just) ImageJ 2.1.0/1.53j; Java 1.8.0_172 [64-bit]; Mac OS X 10.16

d seems legal according to the docs. So I don't know what the issue is here.

The user says that on 1.53c String.pad() is not a recognised String function, but this works on my machine. Original issue is here

ctrueden commented 3 years ago

Thanks for the report, @quantixed. The String.format macro function requires ImageJ 1.53d or newer. The version of ImageJ 1.x shipped with Fiji is a few versions behind due to breaking changes in ImageJ 1.x that the ImageJ2 team still need to work around. In the meantime, you can use the Help > Update ImageJ... command to update the version of ImageJ 1.x bundled with Fiji. Be aware that this command will hard quit your running ImageJ instance after downloading the chosen version.

java.util.IllegalFormatConversionException: d != java.lang.Double in line 1:

Try using %f instead of %d? I guess all numbers in ImageJ1's macro language are doubles?

If you need %d to work, we can refile this issue in the ImageJ1 repository.