これは2つの異なる方法で発生しています。どちらもEDT(スイングコンポーネント)ブロックであり、何もできません。FileNotFoundExceptionがキャッチまたはスローされていない
は最初にを投げていますが、それはプリンタに文字列を送ります。そのため、FileNotFoundExceptionはプリンタが見つからないためです(プリンタが接続されていないことは問題ありません)。 。私はトライキャッチを使用している第2の方法では
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は、Windowsのx64を使用している、JavaはJavaは8 121 X32をSE、8 121
EDIT別のコンピュータWin7のx32の中でテスト済み
SE、そしてそれはすべての罰金です。何ができるかわからない。
エラーまたは例外がスローされず、機能しません。 EDTはちょうどフリーズします。 – tomyforever
println str何をしているのかを確認してください – Pancax
どちらの場合も.print()メソッドが到着するまでは問題ありません。 – tomyforever