pikopong

it's all about knowledge

Java Printing Fix for Linux with CUPS

with 18 comments

Apparently, there’s a bug in Java where people using newer version of CUPS cannot print (can’t even display the print dialog) due to a null pointer exception and this is actually a known bug. So, how do we fix this? For people who use Gnome, you can refer to this page.

However, for people who uses non gui environment such as Fluxbox, Openbox and etc (Gnome and KDE user can use these steps too), you can fix it by editing your CUPS printers configuration file. You can get edit the file at /etc/cups/printers.conf

<DefaultPrinter Printer>
# Printer configuration file for CUPS v1.3.7
# Written by cupsd on 2008-09-08 11:24
.
.
.
Option orientation-requested 3
</Printer>

Make sure you add line 7 to every configuration for every printer you’ve installed. If you cannot find the file, you probably haven’t configured any printer yet.

This fix is simply to make sure CUPS will provide a page orientation setting to Java.

The exception:

Caused by: java.lang.NullPointerException: null attribute
        at sun.print.IPPPrintService.isAttributeValueSupported(IPPPrintService.java:1147)
        at sun.print.ServiceDialog$OrientationPanel.updateInfo(ServiceDialog.java:2121)
        at sun.print.ServiceDialog$PageSetupPanel.updateInfo(ServiceDialog.java:1263)
        at sun.print.ServiceDialog.updatePanels(ServiceDialog.java:437)
        at sun.print.ServiceDialog.initPrintDialog(ServiceDialog.java:195)
        at sun.print.ServiceDialog.(ServiceDialog.java:124)
        at javax.print.ServiceUI.printDialog(ServiceUI.java:188)
        at sun.print.RasterPrinterJob.printDialog(RasterPrinterJob.java:855)
        at sun.print.PSPrinterJob.printDialog(PSPrinterJob.java:421)

Refer to some of the discussions here:

UPDATE: I forgot to add, you need to restart your CUPS after editing the configuration (Thanks to Brandon Bell)

Tested on Slackware 12.1, JDK 1.6 Update 7, CUPS 1.3.7

  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • PDF
  • Print
  • Reddit
  • Slashdot
  • Technorati
  • Twitter

Related Posts

Written by amree

September 9th, 2008 at 10:08 am

Posted in linux

Tagged with , , ,

18 Responses to 'Java Printing Fix for Linux with CUPS'

Subscribe to comments with RSS or TrackBack to 'Java Printing Fix for Linux with CUPS'.

  1. Confirmed to work under Gentoo 2007.1

    Thanks, been killing me since I have to use Matlab for one of my Math classes.

    Also, I had to restart cups via

    /etc/init.d/cupsd restart

    to get this to work for me.

    Brandon BellNo Gravatar

    11 Sep 08 at 07:00 AM

  2. Confirmed to work on Arch. Thanks for this fix!

    CarlNo Gravatar

    5 Oct 08 at 06:00 PM

  3. This does not fix the problem on Kubuntu 8.04 amd64. Help?

    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: null attribute
            at sun.print.IPPPrintService.isAttributeValueSupported(IPPPrintService.java:1100)
            at sun.print.ServiceDialog$OrientationPanel.updateInfo(ServiceDialog.java:2092)
            at sun.print.ServiceDialog$PageSetupPanel.updateInfo(ServiceDialog.java:1234)
            at sun.print.ServiceDialog.updatePanels(ServiceDialog.java:428)
            at sun.print.ServiceDialog.initPrintDialog(ServiceDialog.java:193)
            at sun.print.ServiceDialog.(ServiceDialog.java:141)
            at javax.print.ServiceUI.printDialog(ServiceUI.java:180)
            at sun.print.RasterPrinterJob.printDialog(RasterPrinterJob.java:853)
            at sun.print.PSPrinterJob.printDialog(PSPrinterJob.java:418)
            at com.projity.print.GraphPageable.print(Unknown Source)
            at com.projity.print.PrintPreviewFrame$PrintAction.actionPerformed(Unknown Source)
            at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
            at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169)
            at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
            at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
            at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
            at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:231)
            at java.awt.Component.processMouseEvent(Component.java:5517)
            at javax.swing.JComponent.processMouseEvent(JComponent.java:3135)
            at java.awt.Component.processEvent(Component.java:5282)
            at java.awt.Container.processEvent(Container.java:1966)
            at java.awt.Component.dispatchEventImpl(Component.java:3984)
            at java.awt.Container.dispatchEventImpl(Container.java:2024)
            at java.awt.Component.dispatchEvent(Component.java:3819)
            at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
            at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
            at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
            at java.awt.Container.dispatchEventImpl(Container.java:2010)
            at java.awt.Window.dispatchEventImpl(Window.java:1791)
            at java.awt.Component.dispatchEvent(Component.java:3819)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
            at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

    Philip SchlesingerNo Gravatar

    16 Oct 08 at 03:55 AM

  4. PS I am running sun-java5-jdk 1.5.0_15-b04

    Philip SchlesingerNo Gravatar

    16 Oct 08 at 03:55 AM

  5. Confirmed to work on Fedora 9 with jdk 1.6.
    Thanks :)

    AndriyNo Gravatar

    18 Oct 08 at 12:00 AM

  6. @Philip Schlesinger

    I’m not sure what’s wrong, but it looks like as if you’re still stuck with the same problem, so, maybe you should try the tutorial from the scratch again and make sure this time you follow it correctly.

    By the way, I haven’t test this solution with JDK 5 (the one that you’re using), maybe that’s the problem, try install ng JDK 6 and see if the problem still persists. If it’s not, then, this tutorial is not suitable for JDK 5.

    Good luck trying :)

    amreeNo Gravatar

    18 Oct 08 at 12:10 PM

  7. [...] jsme také na problém s tiskem z Javy pod Linuxem. Museli jsme přidat hack, abychom byli schopni v Linuxu [...]

  8. Doesn’t work for me either (Kubuntu 8.04, CUPS 1.3.7).
    I’ve added the orientation-requested line in my local printers.conf and in printers.conf of my cups server and still get the same java exception.

    ToniNo Gravatar

    24 Oct 08 at 06:54 PM

  9. Confirmed to work on Ubuntu 8.10 – using Buzan’s iMindMap software

    PaulNo Gravatar

    5 Nov 08 at 03:08 AM

  10. [...] girovagato per i meandri della rete per una buona mezz’ora mi sono finalmente imbattuto in questo post (tra l’altro abbastanza recente), che contiene una soluzione molto semplice e rapida al [...]

  11. Works like a charm! Thanks for the easy fix!

    BartNo Gravatar

    14 Nov 08 at 10:45 PM

  12. thx for that workaround.

    ulliNo Gravatar

    8 Jan 09 at 08:27 PM

  13. Confirmed to work for Mandriva Powerpack 2009.0 printing from IntelliJ/Jedit

    DarrenNo Gravatar

    9 Feb 09 at 03:45 PM

  14. Confirmed to work on Suse 11.1 64-bit with java version “1.5.0_16″

    John ZoetebierNo Gravatar

    25 Mar 09 at 06:59 AM

  15. Hi, it works on Debian Squeeze amd64 (jdk 1.6) with JEdit, but not with Eclipse … Any Idea?

    KawanokamiNo Gravatar

    15 Apr 09 at 09:29 PM

  16. It Worrrrrrrrrrrrks! Awesome! Thank you…
    OS: Suse 11.1 x64
    JAVA: Java HotSpot(TM) 64-Bit Server VM (build 1.5.0_18-b02, mixed mode)

    There are 10 types of people, those who understands binary, and those who doesn’t…

    il SantiNo Gravatar

    29 May 09 at 08:57 PM

  17. I spent my day investigating this issue on fedora 8.
    I use a mix of printers for text printing with console text applications, for which I don’t need ppd files, and some on graphical environment, one using java.

    I have printer classes declared to group the printers by function type into the console text applications.

    The java test application (Print2DPrinterJob) from Sun didn’t want to work until I declared a ppd file for each printer and also inserted the “Option orientation-requested 3″ for each printer class. The classes file is named “/etc/cups/classes.conf”.

    Osvaldo Marques JuniorNo Gravatar

    8 Sep 09 at 12:27 PM

  18. OS: SUSE 11.2 x32
    JAVA: Java 1.6.0_04-b12 with Sun Microsystems Inc. (MATLAB)

    Thanks for your help, this fixed the problems nicely.

    Chistian StoecklNo Gravatar

    14 Apr 10 at 09:46 PM

Leave a Reply