Why PrinterState always returns null?

天大地大妈咪最大 提交于 2020-01-17 04:37:06

问题


I'm not to be able to get the PrinterState of my Printers. I have tested the following code on Linux and on Windows (7) with different Printers (Samsung, Brother (only on Linux), Zebra, ...). But in every case the PrinterState and the PrinterStateReasons objects are null.

private void dumpPrinterState() {
PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null); //get printers

for (PrintService printService : printServices) {
  log.info("---- printer: " + printService);
  log.info("---- state: " + printService.getAttribute(PrinterState.class));
  log.info("---- reason: " + printService.getAttribute(PrinterStateReasons.class));
  }
}

Here is the output with my try on Windows:

---- printer: Win32 Printer : ZDesigner KR403
---- state: null
---- reason: null
---- printer: Win32 Printer : Samsung CLP-300 Series
---- state: null
---- reason: null
---- printer: Win32 Printer : Microsoft XPS Document Writer
---- state: null
---- reason: null
---- printer: Win32 Printer : Fax
---- state: null
---- reason: null

Anybody knows whats wrong?


回答1:


You may need to use the toArray() function. An example of how to use this can be found here on SO: SO printer info

Please let me know if this helped you.



来源:https://stackoverflow.com/questions/26985422/why-printerstate-always-returns-null

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!