0

我正在使用带有 java jdk 16 的 NetBeans 12.4,并通过其中的代码实现 Lucene 图像检索。索引的代码在 NetBeans 中的朋友 pc 中运行良好,但是当他将其发送给我并在 Netbeans 中运行它时,在下图 [1] 中显示的关闭编写器中出现错误。下面的代码用于索引器类。谁能帮我解决这个问题?

public class Indexer {

    private final ArrayList<String> images; // The full paths of the images
    private final IndexWriter indexWriter;  // The writer of the indexes

    public Indexer() throws IOException {
        // Reading images full paths from "images" folder
  
        this.images = FileUtils.readFileLines(new File("images"), false);
        // Creating a writer in the "index" folder
        this.indexWriter = LuceneUtils.createIndexWriter("index", true, LuceneUtils.AnalyzerType.WhitespaceAnalyzer);
    }

    public void createIndex() throws IOException {
        /* CEDD: Color and Edge Directivity Descriptor. 
           A compact descriptor for image indexing and retrieval.
         */
        GlobalDocumentBuilder globalDocumentBuilder = new GlobalDocumentBuilder(CEDD.class);
        
        /* The indexes are based on three or more different feature
           types: scalable color, color layout and edge histogram
         */
        globalDocumentBuilder.addExtractor(ScalableColor.class);
        globalDocumentBuilder.addExtractor(ColorLayout.class);
        globalDocumentBuilder.addExtractor(EdgeHistogram.class);

        // Looping throught the images and creating the indexes for each one
        for (String imagePath : images) {
            System.out.println("Indexing " + imagePath);
            try {
                // Exctracting the image object
                BufferedImage image = ImageIO.read(new FileInputStream(imagePath));
                // Creating the document(index) for the image
                Document document = globalDocumentBuilder.createDocument(image, imagePath);
                // Adding the document to index folder
                this.indexWriter.addDocument(document);
            } catch (IOException e) {
                System.err.println("Error reading image or indexing it.");
            }
        }
    }

    public void close() throws IOException {
        // Closing the writer
        LuceneUtils.closeWriter(this.indexWriter);
        System.out.println("Finished indexing.");
    }

链接中的此图像是尝试以关闭方法关闭编写器后发生的错误。[1]:https ://i.stack.imgur.com/Hho4c.png

4

0 回答 0