【问题标题】:missing javax.swing缺少 javax.swing
【发布时间】:2012-03-05 16:13:31
【问题描述】:

我正在尝试使用 jpedal 的 pdf 库,使用此处找到的代码 sn-p:http://www.jpedal.org/simple_image_example.php

/**instance of PdfDecoder to convert PDF into image*/
PdfDecoder decode_pdf = new PdfDecoder(true);

/**set mappings for non-embedded fonts to use*/
FontMappings.setFontReplacements();

/**open the PDF file - can also be a URL or a byte array*/
try {
        decode_pdf.openPdfFile("C:/myPDF.pdf"); //file
        //decode_pdf.openPdfFile("C:/myPDF.pdf", "password"); //encrypted file
        //decode_pdf.openPdfArray(bytes); //bytes is byte[] array with PDF
        //decode_pdf.openPdfFileFromURL("http://www.mysite.com/myPDF.pdf",false);

        /**get page 1 as an image*/
        //page range if you want to extract all pages with a loop
        //int start = 1,  end = decode_pdf.getPageCount();
        BufferedImage img=decode_pdf.getPageAsImage(1);

    /**close the pdf file*/
    decode_pdf.closePdfFile();

} catch (PdfException e) {
    e.printStackTrace();
}

但是在这一行:

decode_pdf.openPdfFile("C:/myPDF.pdf"); //file

Eclipse 报错:

类型 javax.swing.JPanel 无法解析。是间接的 从所需的 .class 文件中引用

好像我缺少 javax.swing.*

Intellisence 确实给了我其他 javax.* 选项,但没有给我 Swing 类。

我已经在谷歌上搜索过这个,但我没有找到解决方案。

有什么想法吗?

【问题讨论】:

  • 通常这是核心 java 安装的一部分。你确定你安装正确了吗?
  • 实际使用的是哪个版本/类型的 java?
  • 在 cmd 中使用“java -version”命令我得到:java 版本“1.7.0_02”Java(TM) SE Runtime Environment (build 1.7.0_02-b13) Java HotSpot(TM) 64- Bit Server VM(build 22.0-b10,混合模式)
  • 能否在早期的 JDK 下运行相同的代码?例如。 1.6?
  • 我现在要试试这个。

标签: java eclipse swing import


【解决方案1】:

没有比这更清楚的了: http://www.jpedal.org/PDFblog/2011/09/java-is-not-android/

看来我要使用的库根本不兼容android。

也不是最后一句:

这使得将 Java PDF 查看器转换为 Android 成为一项主要任务。

感谢你粉碎了我的最后一点希望 jpedal...

【讨论】:

    【解决方案2】:

    我怀疑路径没有解析,试试这个

     decode_pdf.openPdfFile("C:\\myPDF.pdf");
    

    【讨论】:

    • 请参阅我在使用代码 sn-p (OpenPdfArray, OpenPdfFileFromUrl) 中注释的其他方法时也遇到错误
    猜你喜欢
    • 1970-01-01
    • 2020-10-21
    • 2012-12-20
    • 2021-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-17
    • 2021-09-22
    相关资源
    最近更新 更多