【发布时间】:2013-01-08 13:21:36
【问题描述】:
请原谅我对 Java 导入的困惑——我来自 Python 背景。
我有一些使用 itext 库的代码:
public static void makeADoc (Person p, String outfile) throws DocumentException,FileNotFoundException{
Document document = new Document;
PdfWriter.getInstance(document, new FileOutputStream(outfile));
document.open();
document.add(new Paragraph("Hello " + p.getFirst() + ",\n" + "You've just won the lotto!"));
document.close();
}
我已将适用的 itext-pdf jar 文件添加到项目的路径中。我已经在这个类的开头使用通配符导入语句导入了整个库:
import com.itextpdf.*;
然而,对于 Document 对象和 DocumentException 和 FileNotFound Exception 对象,Eclipse 仍然给我带有红色下划线的错误。我可以选择从 itextpdf 导入 Document 类,但我的通配符语句似乎应该涵盖了这一点。这是怎么回事?
【问题讨论】:
-
在 Eclipse 中,按
Ctrl-o,这将执行 Organize Imports,这将解决您的头痛问题。如果存在名称冲突,您只需选择正确的类名。