0

I have the following code

private static Properties printProperties = new Properties();

public void print() {
        PrintJob printJob = null;
        try {
            printJob = getToolkit().getPrintJob(this, "Draw app", printProperties);
        } catch (Exception e) {
        System.out.println(e.getMessage());
        }
        if (printJob == null)
            return;

And when I'm clicking on the printing button in my menu I get a NullpointerException, which by the PrintJob class API is invoked by a null frame problem , If Someone can explain how to solve this problem. Thanks for helping.

LBes
  • 3,366
  • 1
  • 32
  • 66
Barak michaeli
  • 113
  • 1
  • 11
  • Where exactly does the NullPointerException occur? I suppose it's because getToolkit() returns null – LBes Aug 23 '16 at 13:19
  • Well it seems because the getPrintJob() method , the getToolkit() isn't null. – Barak michaeli Aug 23 '16 at 13:21
  • I don't see how it could be because of that. You usually get a NullPointerException when trying to invoke a method on a null object. If printjob is null that is not a problem because you're not trying to call anything or access anything through that variable. I would focus on the getToolkit method. What it its code? – LBes Aug 23 '16 at 13:27
  • Just before pasting the code , when I check if the getToolkit() method is returning null or the other method it seems like both of them don't returning null objects. I used getToolkit().equals(null) - which was false. – Barak michaeli Aug 23 '16 at 13:33
  • First you should use "==" to check whether it is null or not. And again I ask the same question but you should get an error saying where the NullPointerException does occur. Please indicate that. It would help both of us in solving this issue. Also what does getToolkit() do? – LBes Aug 23 '16 at 13:37
  • This code doesn't compile. Please provide us [mcve] accordubg to [ask] – xenteros Aug 23 '16 at 15:54

0 Answers0