0

I have been a lot of digging into resolving a null pointer exception for a BufferedImage. The code is below:

this.v.calGrad.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                BufferedImage img = null;
                Graphics2D g = null;
                try {
                    img = ImageIO.read(new File(fileToManipulate.getPath()));
                    g = img.createGraphics();
                } catch (IOException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }


                Orientation o = Orientation.HOR;
                ms.applySobel(fileToManipulate.getPath(), o);
                g.dispose();
            }
        });

So I know the problem line g = img.createGraphics();. This is because img is apparently null. I thought this was due to the fact that BufferedImage is set to null. So I tried creating a global variable and setting the img. However that did not change the result. I also checked fileToManipulate and it does exist.

Any assistance would be appreciated.

Thanks

NSaid
  • 689
  • 2
  • 16
  • 32

0 Answers0