pikopong

it’s all about knowledge

Java Printing Fix for Linux with CUPS

with 16 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

Written by mree

September 9th, 2008 at 10:08 am

Posted in linux

16 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 Bell

    11 Sep 08 at 7:00 am

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

    Carl

    5 Oct 08 at 6: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 Schlesinger

    16 Oct 08 at 3:55 am

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

    Philip Schlesinger

    16 Oct 08 at 3:55 am

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

    Andriy

    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 :)

    mree

    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.

    Toni

    24 Oct 08 at 6:54 pm

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

    Paul

    5 Nov 08 at 3: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!

    Bart

    14 Nov 08 at 10:45 pm

  12. thx for that workaround.

    ulli

    8 Jan 09 at 8:27 pm

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

    Darren

    9 Feb 09 at 3:45 pm

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

    John Zoetebier

    25 Mar 09 at 6:59 am

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

    Kawanokami

    15 Apr 09 at 9: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 Santi

    29 May 09 at 8:57 pm

Leave a Reply

Security Code: