【问题标题】:retrieving data from a link list of File and comparing the obtain image with the existing image从 File 的链接列表中检索数据并将获取的图像与现有图像进行比较
【发布时间】:2017-06-28 14:59:34
【问题描述】:

我正在尝试从文件的链接列表中获取文件,然后将获得的图像与 imageView 上的现有图像进行比较,但它给出了空指针异常在此处输入代码

files.stream().map((file) -> file.toPath().toString()).forEachOrdered((string) -> {
try {
    Image source =new Image(new FileInputStream(string));
    if(source==image){
        stringFilePath=string;
    }
} catch (FileNotFoundException ex) {
    Logger.getLogger(SecondFrameController.class.getName()).log(Level.SEVERE, null, ex);
}

我也用for循环试过了,问题依旧存在

  for(File file:files)
            {
                 String string= file.toPath().toString();
                        try {
                            Image source =new Image(new FileInputStream(string));
                             if(source==image){
                                   stringFilePath=string;
                             }
                        } catch (FileNotFoundException ex) {
                            Logger.getLogger(SecondFrameController.class.getName()).log(Level.SEVERE, null, ex);
                        }
            }

【问题讨论】:

    标签: java linked-list image-comparison


    【解决方案1】:

    在您的情况下,== 运算符永远不会返回 true,因为它用于识别实例,而不是比较图像。
    有关== 对象的更多信息,请参阅此答案:http://stackoverflow.com/a/19966154/2284641

    尝试使用Image 类的方法,该方法可用于将其与另一个Image 实例进行比较。

    【讨论】:

      猜你喜欢
      • 2013-04-11
      • 2012-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-04
      相关资源
      最近更新 更多