A quick search on Google shows that some people have had problems like
this when no valid printers were on line, or when CUPS wasn't properly
set up. So I plugged my USB printer in and turned it on, but still get
the same exception.
Netbeans does not crash, but it also does not find my valid printer. So
I'm pretty sure my printer is set up wrong, however, it would be nice
to avoid crashing without catching and ignoring the exception.
Anyone know anything about this?
Or, can anyone point me to a good tutorial on getting a valid
PageFormat without asking the machine to look for a printer?
The exception:
Exception in thread "main" java.lang.IndexOutOfBoundsException
at
java.io.BufferedInputStream.read(BufferedInputStream.java:306)
at sun.net.www.MeteredStream.read(MeteredStream.java:116)
at java.io.FilterInputStream.read(FilterInputStream.java:111)
at
sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(HttpURLConnection.java:2123)
at java.io.DataInputStream.read(DataInputStream.java:134)
at
sun.print.IPPPrintService.readIPPResponse(IPPPrintService.java:1589)
at
sun.print.IPPPrintService.opGetAttributes(IPPPrintService.java:1436)
at
sun.print.IPPPrintService.initAttributes(IPPPrintService.java:333)
at
sun.print.IPPPrintService.getSupportedDocFlavors(IPPPrintService.java:707)
at
sun.print.IPPPrintService.isDocFlavorSupported(IPPPrintService.java:783)
at
sun.print.RasterPrinterJob.getPrintService(RasterPrinterJob.java:428)
at
sun.print.RasterPrinterJob.defaultPage(RasterPrinterJob.java:1420)
at java.awt.print.PrinterJob.defaultPage(PrinterJob.java:361)
at RandomWords$RandomWordsPage.<init>(RandomWords.java:223)
at RandomWords.main(RandomWords.java:416)
The code:
public static class MyWordsPage extends JPanel implements Printable
{
PageFormat format;
PrinterJob printJob;
MyWordsPage( String[] myWords )
{
super();
this.printJob = PrinterJob.getPrinterJob();
this.format = this.printJob.defaultPage();
...
joseph_daniel_zukiger@yahoo.com - 10 Jan 2006 21:44 GMT
Anybody want to hit me with a clue stick?
Anybody have any good samples on getting a valid PageFormat? Do I just
catch all exceptions, and assume that if an exception comes up that no
valid printer was found? And shouldn the runtime be throwing
IndexOutOfBoundsException? More specifically,
> The code:
>
[quoted text clipped - 9 lines]
> this.format = this.printJob.defaultPage();
> ...
is there something I should be doing before calling defautlPage()? Is
calling defaultPage from a JPanel constructor a bad idea? (I think it
is. Perhaps this will go away when I re-organize the code correctly.)
> A quick search on Google shows that some people have had problems like
> this when no valid printers were on line, or when CUPS wasn't properly
[quoted text clipped - 37 lines]
> at RandomWords$RandomWordsPage.<init>(RandomWords.java:223)
> at RandomWords.main(RandomWords.java:416)