ClassCastException ImageExport.makeImage 3.2.3

User 2082812c83

29-01-2007 19:00:16

Hi,





After an upgrade to JChem 3.2.3 from 3.1.1 I am seeing the following class cast exception when attempting to convert a molecule object into a PNG:





java.lang.ClassCastException


at chemaxon.marvin.modules.ImageExport.makeImage(ImageExport.java:375)


at chemaxon.marvin.modules.ImageExport.convert(ImageExport.java:391)


at chemaxon.marvin.modules.PngExport.convert(PngExport.java:65)


at chemaxon.struc.Molecule.exportToObject(Molecule.java:1302)


at chemaxon.struc.Molecule.exportToObject(Molecule.java:1267)


at chemaxon.struc.Molecule.toObject(Molecule.java:1231)





The call I am making that causing this exception and which ran correctly under 3.1.1 is:





byte[] molba = (byte[])mol.toObject


("png:w" + (4*width) + ",h" + (4*height) + ",b32,#9fffffff");





Where the string argument passed to the toObject method comes out as





"png:w664,h400,b32,#9fffffff"





As I said above this code works with JChem Base 3.1.1. Could you please provide either a fix to this issue or a workaround that can be used in place of the existing code to generate a PNG from a Molecule object.





Thanks,





James

ChemAxon 7c2d26e5cf

31-01-2007 16:21:39

I don't think it would be a bug. As I see, you have mistyped the value of the background color. Since, an invalid value is given, Marvin can not recognize it and throws an exception.


Instead of #9fffffff, use #9fffff.


The syntax for giving a color is #rrggbb where rr is the red, gg is the green and bb is the blue component of the color. Each component is represented by a hexadecimal value (two characters whose value can be 0 - 9 or a - f ).


http://www.chemaxon.com/marvin/doc/user/images-doc.html

User 2082812c83

31-01-2007 17:06:33

Tamas,





Thanks for tracking this down. Correcting the color specification fixed the problem.





It might be a good idea in the next release of JChem Base to change the exception that is thrown under these circumstance so that it is possible to deduce what is causing the problem.





An alternative to changing the exception would be to allow the call with an incorrect color designation to produce an image, as was done under JChem Base 3.1.1 using a default color (it seems it used to default to white) as this is a much more desirable outcome than a somewhat obscure exception.





Thanks again for your help. We will be more careful with our color designations in the future.





James

ChemAxon 7c2d26e5cf

01-02-2007 14:29:13

Thanks for the suggestion.


I've fixed it. In the future (since Marvin 4.1.6), an IllegalArgumentException will be thrown if the color value is invalid.