在线程“main”中获取异常java.lang.NullPointerException下面的代码有什么问题

时间:2016-08-23 07:40:29

标签: java pointers exception null

[10:35:04] I/hosted - Using the selenium server at https://hub-cloud.browserstack.com/wd/hub
[10:35:04] I/launcher - Running 1 instances of WebDriver
[10:35:04] E/launcher - EPROTO write EPROTO
[10:35:04] E/launcher - Error: EPROTO write EPROTO

1 个答案:

答案 0 :(得分:0)

试试这个 - 确保\被转义。在Windows上,必须转义单反斜杠。请参阅下面的代码。

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class ImageTest {
public static void main(String args[]) {
    ImageTest imageTest = new ImageTest();
    imageTest.testImage();

}

void testImage() {
    int x = 10;
    int y = 10;
    int w = 24;
    int h = 44;
    String path = "C:\\Users\\xxx\\yyy\\Documents\\M\\tumblr_nz324ifAzI1sgxxaao1_500.jpg";

    System.out.println("Path===>" + path);
    BufferedImage out = null;
    BufferedImage image = null;
    try {
        image = ImageIO.read(new File(path));
    } catch (IOException e) {
        e.printStackTrace();
    }
}

}