Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » NullPointerException printing on mac
icon5.gif  NullPointerException printing on mac [message #514824] Tue, 16 February 2010 18:17 Go to next message
Paul Wells is currently offline Paul Wells
Messages: 7
Registered: January 2010
Junior Member
If I run the below code on Mac OS X 10.6.2 then creation of the GC causes a NullPointerException to be thrown. If I run the same code on Windows 7 it is fine.

In both cases I'm building/running with
org.eclipse.swt_3.5.1.v3555a.jar

then the platform dependent jar of the same version.

org.eclipse.swt.cocoa.macosx.x86_64_3.5.1.v3555a.jar

in the case of the mac.

Thanks in advance for any help with getting printing working on the mac.

Paul

* * * *

package com.test.printer;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.printing.PrintDialog;
import org.eclipse.swt.printing.Printer;
import org.eclipse.swt.printing.PrinterData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class PrinterTest
{
public static void main(String[] arguments)
{
final Display display = new Display();
final Shell shell = new Shell(display);
final Button printButton = new Button(shell, SWT.PUSH);
printButton.setText("print");
printButton.pack();
printButton.setLocation(10, 68);
printButton.addSelectionListener(new SelectionAdapter()
{
@Override
public void widgetSelected(SelectionEvent e)
{
final PrintDialog dialog = new PrintDialog(shell);
final PrinterData printerData = dialog.open();
if (printerData == null)
return;
final Printer printer = new Printer(printerData);
try
{
new GC(printer);
System.out.println("GC created");
}
catch (NullPointerException exception)
{
System.out.println("NPE while constructing GC");
}
}
});
shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
Re: NullPointerException printing on mac [message #515071 is a reply to message #514824] Wed, 17 February 2010 16:07 Go to previous messageGo to next message
Grant Gayed is currently offline Grant Gayed
Messages: 2151
Registered: July 2009
Senior Member
Hi Paul,

You're seeing an swt bug that is fixed [1] in the 3.6 stream. I don't think
there's a way to make this case work with your current swt jar, so you can
either use a 3.6-stream milestone release such as
http://download.eclipse.org/eclipse/downloads/drops/S-3.6M5- 201001291300/index.php ,
or if this is not possible, use the 3.5.1 carbon-based swt instead since it
does not show this problem. (If attempting to run the carbon port on 64-bit
OS X take note of http://www.eclipse.org/swt/faq.php#cocoa32launch ).

[1] The NPE is fixed at least, though there are now many warnings written to
stderr. I've logged https://bugs.eclipse.org/bugs/show_bug.cgi?id=303074
for this.

Grant


"Paul Wells" <paul.wells@agilej.com> wrote in message
news:hlenf8$dgj$1@build.eclipse.org...
> If I run the below code on Mac OS X 10.6.2 then creation of the GC causes
a NullPointerException to be thrown. If I run the same code on Windows 7 it
is fine.
>
> In both cases I'm building/running with
> org.eclipse.swt_3.5.1.v3555a.jar
>
> then the platform dependent jar of the same version.
>
> org.eclipse.swt.cocoa.macosx.x86_64_3.5.1.v3555a.jar
>
> in the case of the mac.
>
> Thanks in advance for any help with getting printing working on the mac.
>
> Paul
>
> * * * *
>
> package com.test.printer;
>
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.events.SelectionAdapter;
> import org.eclipse.swt.events.SelectionEvent;
> import org.eclipse.swt.graphics.GC;
> import org.eclipse.swt.printing.PrintDialog;
> import org.eclipse.swt.printing.Printer;
> import org.eclipse.swt.printing.PrinterData;
> import org.eclipse.swt.widgets.Button;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Shell;
>
> public class PrinterTest
> {
> public static void main(String[] arguments)
> {
> final Display display = new Display();
> final Shell shell = new Shell(display);
> final Button printButton = new Button(shell, SWT.PUSH);
> printButton.setText("print");
> printButton.pack();
> printButton.setLocation(10, 68);
> printButton.addSelectionListener(new SelectionAdapter()
> {
> @Override
> public void widgetSelected(SelectionEvent e)
> {
> final PrintDialog dialog = new PrintDialog(shell);
> final PrinterData printerData = dialog.open();
> if (printerData == null)
> return;
> final Printer printer = new Printer(printerData);
> try
> {
> new GC(printer);
> System.out.println("GC created");
> }
> catch (NullPointerException exception)
> {
> System.out.println("NPE while constructing GC");
> }
> }
> });
> shell.open();
> while (!shell.isDisposed())
> {
> if (!display.readAndDispatch())
> display.sleep();
> }
> display.dispose();
> }
> }
>
Re: NullPointerException printing on mac [message #515148 is a reply to message #515071] Wed, 17 February 2010 21:43 Go to previous message
Paul Wells is currently offline Paul Wells
Messages: 7
Registered: January 2010
Junior Member
Grant,

Thanks for confirming that this is a known issue and that it is being fixed.

I cannot run my application on 3.6, there are other dependency issues thrown up as I try to install, so I cannot confirm that it is resolved.

Thanks again for your help

Paul
Previous Topic:VerifyListener, statemask
Next Topic:SWT Toggle Button mousehover
Goto Forum:
  


Current Time: Tue Oct 21 15:16:17 GMT 2014

Powered by FUDForum. Page generated in 0.03247 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software