-1

理由を理解してください:)私のプログラムは「try」行に到達しますが、「キャッチ」をスキップしているようです。スタックトレースを出力していますが...キャッチでJOptionPaneを使用していますが、System.out.println( ) 動作していません。コード:

import java.awt.AWTException;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import javax.imageio.ImageIO;
import javax.swing.JOptionPane;


public class main {

    public static void main(String[] args) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
        Calendar cal = Calendar.getInstance();
        String fileName = dateFormat.format(cal.getTime());
        Rectangle rectangle = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
        BufferedImage bufferedImage;
        try {
            bufferedImage = new Robot().createScreenCapture(rectangle);
            try
            {
                ImageIO.write(bufferedImage, "jpg", new File("c:/temp/ScrenShots/"+fileName+".jpg"));
            } catch (IOException e)
            {
                JOptionPane frame = null;
                JOptionPane.showMessageDialog(frame,"Failed to take screen-shot", "ScreenShots", JOptionPane.ERROR_MESSAGE);
                e.printStackTrace();
            }
        } catch (AWTException e) {
            JOptionPane frame = null;
            JOptionPane.showMessageDialog(frame,"AWT Error", "ScreenShots", JOptionPane.ERROR_MESSAGE);
            e.printStackTrace();
        }

    }

}

例外:

java.io.FileNotFoundException: c:\temp\ScrenShots\20.10.2014.jpg (The system cannot find the path specified)
    at java.io.RandomAccessFile.open(Native Method)
    at java.io.RandomAccessFile.<init>(Unknown Source)
    at javax.imageio.stream.FileImageOutputStream.<init>(Unknown Source)
    at com.sun.imageio.spi.FileImageOutputStreamSpi.createOutputStreamInstance(Unknown Source)
    at javax.imageio.ImageIO.createImageOutputStream(Unknown Source)
    at javax.imageio.ImageIO.write(Unknown Source)
    at main.main(main.java:26)
Exception in thread "main" java.lang.NullPointerException
    at javax.imageio.ImageIO.write(Unknown Source)
    at main.main(main.java:26)
4

1 に答える 1