JAVA-com/lowagie/textDocumentException中的怪异NoClassDefFoundError [英] JAVA - Weird NoClassDefFoundError in : com/lowagie/textDocumentException

查看:217
本文介绍了JAVA-com/lowagie/textDocumentException中的怪异NoClassDefFoundError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

就是这种情况.我需要将PDF生成添加到已经具有PNG生成的程序中.最初涉及的2个类是: ActionUsuels ,从中调用 CaptureImage3D 的构造函数.

This is the situation. I need to add PDF generation to a program that already has PNG generation. Initially the 2 classes involved are : ActionUsuels From where the constructor of CaptureImage3D is called.

当我添加PDF生成时,我在CaptureImage3D类中添加了一个方法. 在添加PDF生成之前,PNG生成可以正常工作.但是现在当我尝试生成PNG时,得到了NoClassDefFoundError:com/lowagie/text/DocumentException.

When I added the PDF generation I added a method at the CaptureImage3D class. Before adding the PDF generation, the PNG generation worked correctly. But now when I try to do the PNG generation, I get a : NoClassDefFoundError: com/lowagie/text/DocumentException.

我知道这意味着无法从类路径中读取类:DocumentException(来自itext jar),但是:

I know it means that the class : DocumentException (from the itext jar) can't be read from the classpath but :

  1. 永远不会调用PDF生成方法.
  2. 在进入CaptureImage3D的构造函数之前会生成异常.
  3. 考虑以下PDF生成方法:
  1. The PDF generation method is NEVER called.
  2. The exception is generated before entering the constructor of CaptureImage3D.
  3. Consider the following PDF generation method:

Code:

  public void captureImagePDF(File imageFile)
  {

        System.out.println("Pdf appelé");

        // Dimension (en pixels) de l'image a sauvegarder dans le fichier
        Dimension dim = new Dimension(512, 512);

        // On recupere l'image (pixmap) rendue par le canvas 3D offscreen
        BufferedImage myBufferedImage = offScreenCanvas.getOffScreenImage(dim);

        // On recupere le contexte graphique de l'image finale de sortie
        Graphics2D gc = myBufferedImage.createGraphics();

        gc.drawImage(myBufferedImage, 0, 0, null);

        Document myPDF = new Document(PageSize.A4, 50, 50, 50, 50);

        PdfWriter myWriter = null;

        try 
        {
            myWriter = PdfWriter.getInstance(myPDF, new FileOutputStream(imageFile));
        } 


        catch (FileNotFoundException e) 
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 

        catch (DocumentException e) 
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


        myPDF.open();
        PdfContentByte cb = myWriter.getDirectContent();
        cb.saveState();
        Image image = null;

        try {
            image = Image.getInstance(myBufferedImage,null);
        } 

        catch (BadElementException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 

        catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        try {
                cb.addImage(image);
        } 
        catch (DocumentException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
        }


  }

当我评论所有try/catch团体时,一切正常!

When I comment all the try/catch blocs, everything works fine !!!

我再次重复:从来没有调用captureImagePDF.甚至CaptureImage3D的构造函数也永远不会被访问. (应该是,但是之前有例外).是的,我在类路径中有itext.

I repeat again: captureImagePDF is never called. And even the constructor of CaptureImage3D is never accessed. (it should be, but the exception is raised before). And yes, I have itext in the classpath.

我发现一个奇怪的事实是,从来没有在任何地方调用过的一段代码会导致出现异常!

I find it weird the fact that a piece of code, that is never called anywhere, causes the apparition of the exception!

不要犹豫,要求澄清!

有什么主意吗?

谢谢

推荐答案

您有一个DocumentException陷阱的事实意味着装入程序必须装入该类,以便系统可以捕获它. :-)

The fact that you have a catch for DocumentException means that the loader has to load the class, so that the system can catch it. :-)

如果要避免在类路径中使用iText jar,则需要捕获更高的内容,或者(如您所说)根本不捕获. :-P

If you want to avoid having to have the iText jar in your classpath, catch something higher up, or (like you said) don't catch at all. :-P

这篇关于JAVA-com/lowagie/textDocumentException中的怪异NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆