BufferedImage的JAVA NullPointerException

我一直在努力解决BufferedImage的空指针异常。代码如下:

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();
            }
        });

所以我知道问题行g = img.createGraphics();。这是因为img显然为空。我认为这是由于BufferedImage设置为null所致。所以我尝试创建一个全局变量并设置img。但是,这并没有改变结果。我还检查了fileToManipulate,它确实存在。

任何帮助将不胜感激。

谢谢

qwe541171815 回答:BufferedImage的JAVA NullPointerException

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2882591.html

大家都在问