NullPointerException when using MolPainter

User c23c5e9da4

16-04-2009 07:12:29

This example generates this


Exception in thread "main" java.lang.NullPointerException
    at java.awt.geom.Area.<init>(Area.java:54)
    at chemaxon.marvin.paint.internal.MolPainter.coverCrossingBonds(Unknown Source)
    at chemaxon.marvin.paint.internal.MolPainter.bondLine(Unknown Source)
    at chemaxon.marvin.paint.internal.MolPainter.bondLine(Unknown Source)
    at chemaxon.marvin.paint.internal.MolPainter.paintBond(Unknown Source)
    at chemaxon.marvin.paint.internal.MolPainter.paintObjects(Unknown Source)
    at chemaxon.marvin.paint.internal.MolPainter.paintDocument(Unknown Source)
    at chemaxon.marvin.MolPrinter.paint(Unknown Source)
    at com.vpharm.library.cfx.chemistry.MolPainterBugReport.main(MolPainterBugReport.java:22)


when using the latest Marvin


import chemaxon.formats.MolImporter;
import chemaxon.marvin.MolPrinter;
import chemaxon.struc.Molecule;

import java.awt.*;
import java.awt.image.BufferedImage;

public class MolPainterBugReport {
    public static void main(String[] args) throws Exception {
        Molecule mol = MolImporter.importMol("C1CC2CC1CN2");

        int width = 300;
        int height = 300;

        BufferedImage buff = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_INDEXED);
        Graphics g = buff.getGraphics();
        MolPrinter p = new MolPrinter(mol);
        Rectangle r = new Rectangle(300, 300);
        p.setScale(p.maxScale(r));
        p.paint(g, r);
    }
}

ChemAxon e500b51457

16-04-2009 21:12:44

Hello,


We are sorry for the problem, we will fix it by the 5.2.2. version.
Util then, you can use this workaround in your code:
if (g.getClip() == null){
g.setClip(r);
}

before the p.paint(g, r); call.


 


Best Regards,


Erika

ChemAxon e500b51457

19-10-2009 07:58:52

Hello,


The correction is available in Marvin, so your example
should work without the workaround.


Best regards,


Erika.