Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

IndexOutOfBoundsException getting a PrinterJob.defaultPage() on a Linux box

Thread view: 
joseph_daniel_zukiger@yahoo.com - 10 Jan 2006 02:34 GMT
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)


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.