java中打印导致jvm崩溃
正常情况下,是可以打印成功的(连接的是别人的网络打印机),当我把网络断掉的时候,再运行程序,结果就在运行 job.print(doc, pras);时jvm崩溃,这个程序打印的是一张拓扑图,AbstractTopoGraph extends GPGraph;
代码如下:
public void creatPrintTopo(AbstractTopoGraph g) {
DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
PrintService printService[] = PrintServiceLookup
.lookupPrintServices(flavor, pras);
PrintService defaultService = PrintServiceLookup
.lookupDefaultPrintService();
PrintService service = ServiceUI.printDialog(null, 200, 200,
printService, defaultService,
flavor, pras);
if (service != null) {
try {
DocPrintJob job = service.createPrintJob();
DocAttributeSet das = new HashDocAttributeSet();
Doc doc = new SimpleDoc(g, flavor, das);
job.print(doc, pras);
}
catch (PrintException pe) {
pe.printStackTrace();
}
}
else {
JOptionPane.showConfirmDialog(null,
"Sorry, Printer Job is Empty, Print Cancelled! ", "Empty ",
JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE);
}
}
------解决方案--------------------找写DocPrintJob的人
------解决方案--------------------你给的代码不是很全
最有可能出现错误的地方可能是DocPrintJob中print这个方法
最好把这部分代码也贴出来
------解决方案--------------------帮顶,学习中!
------解决方案--------------------