它发生在2种不同的方法中,它既包含EDT(swing组件)块,也不能做任何事情。FileNotFoundException没有被捕获或抛出
在第一个我与试图抛出,它发送字符串到打印机,所以FileNotFoundException异常是因为打印机没有被发现(这不是一个问题,我知道打印机未连接。) 。
public void methodOne() throws PrintException, FileNotFoundException{
...
//a lot of lines
...
//not working code:
PrintService service = PrintServiceLookup.lookupDefaultPrintService();
DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
DocPrintJob pj = service.createPrintJob();
Doc doc=new SimpleDoc(bytes,flavor,null);
//and here is where the exception should be thrown:
pj.print(doc, null);
}
在我使用尝试捕捉第二种方法,它发送一个字符串到打印机了。
public void methodTwo(){
String code2 = "1B700096FA";//hex
FileOutputStream os = null;
PrintStream ps=null;
try {
os = new FileOutputStream("LPT1:POS-58");
ps= new PrintStream(os);
ps.print(toAscii(code2)); //--> here it freezes
System.out.println("cashopen ");//--> not even arrives here
} catch (FileNotFoundException e) { //--> the exception is not being catched
JOptionPane.showMessageDialog(this, "Can't open the cashdrawer");
e.printStackTrace();
}finally{
ps.close();}
}
}
public StringBuilder toAscii(String hex){
StringBuilder output = new StringBuilder();
for (int i = 0; i < hex.length(); i+=2) {
String str = hex.substring(i, i+2);
output.append((char)Integer.parseInt(str, 16));
}
return output;
}
其他例外正在工作。任何想法是受欢迎的。我使用Eclipse,64位的Windows,Java SE的8 121
编辑
在另一台电脑Win7的32倍测试的Java SE 8 121的32倍,而这一切都很好。不知道可能是什么。
不工作,不抛出任何错误或异常。美国东部时间刚刚冻结 – tomyforever
println str查看它在做什么 – Pancax
在两种情况下它都到达.print()方法,这一切都很好。 – tomyforever