NullPointerException
Java サーブレットを実行するとエラーが発生します。
これが私のコードです:
out.println("<image>");
int BI_WIDTH = 1000;
int BI_HEIGHT = 1400;
BufferedImage bImage = new BufferedImage(BI_WIDTH, BI_HEIGHT,BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = bImage.createGraphics();
g2d.setBackground(Color.WHITE);
g2d.clearRect(0, 0, BI_WIDTH, BI_HEIGHT);
g2d.setColor(Color.BLACK);
BasicStroke bs = new BasicStroke(10);
g2d.setStroke(bs);
g2d.drawLine(30, 30, 800, 30);
//out.println("<status ref=\"done\" />");
//out.println("<status ref=\"" + bImage.getWidth() + "x" + bImage.getHeight() + "\" />");
out.println("<status ref=\"" + bImage.getWidth() + "x" + bImage.getHeight() + "\" />");
try {
ImageIO.write(bImage, "jpg", new File("C:\\test.jpg"));
} catch (IOException e) {
out.println("<status ref=\"" + e +"\" />");
}
out.println("</image>");
Tomcat から取得しているエラーは次のとおりです。
description The server encountered an internal error () that prevented it from fulfilling this request.exception
java.lang.NullPointerException
javax.imageio.ImageIO.write(ImageIO.java:1538)
SendBasicReport.doGet(SendBasicReport.java:62)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)