如何解决 Eclipse 中的以下错误?

How to solve the following error in Eclipse?

我有以下代码,这是根据维基百科索引创建图表。此代码试图将维基百科图表导入 graph.db 目录。

// Copyright (c) 2012 Mirko Nasato
//

package org.graphipedia.dataimport.neo4j;

import java.util.HashMap;
import java.util.Map;

import org.neo4j.unsafe.batchinsert.BatchInserter;
import org.neo4j.unsafe.batchinsert.BatchInserters;

public class ImportGraph {

    private final BatchInserter inserter;
    private final Map<String, Long> inMemoryIndex;

    public ImportGraph(String dataDir) {
        inserter = BatchInserters.inserter(dataDir);
        inserter.createDeferredSchemaIndex(WikiLabel.Page).on("title").create();
        inMemoryIndex = new HashMap<String, Long>();
    }

    public static void main(String[] args) throws Exception {
        if (args.length < 2) {
            System.out.println("USAGE: ImportGraph <input-file> <data-dir>");
            System.exit(255);
        }
        String inputFile = args[0];
        String dataDir = args[1];
        ImportGraph importer = new ImportGraph(dataDir);
        importer.createNodes(inputFile);
        importer.createRelationships(inputFile);
        importer.finish();
    }

    public void createNodes(String fileName) throws Exception {
        System.out.println("Importing pages...");
        NodeCreator nodeCreator = new NodeCreator(inserter, inMemoryIndex);
        long startTime = System.currentTimeMillis();
        nodeCreator.parse(fileName);
        long elapsedSeconds = (System.currentTimeMillis() - startTime) / 1000;
        System.out.printf("\n%d pages imported in %d seconds.\n", nodeCreator.getPageCount(), elapsedSeconds);
    }

    public void createRelationships(String fileName) throws Exception {
        System.out.println("Importing links...");
        RelationshipCreator relationshipCreator = new RelationshipCreator(inserter, inMemoryIndex);
        long startTime = System.currentTimeMillis();
        relationshipCreator.parse(fileName);
        long elapsedSeconds = (System.currentTimeMillis() - startTime) / 1000;
        System.out.printf("\n%d links imported in %d seconds; %d broken links ignored\n",
                relationshipCreator.getLinkCount(), elapsedSeconds, relationshipCreator.getBadLinkCount());
    }

    public void finish() {
        inserter.shutdown();
    }

}

但是,每次我 运行 这段代码,我都会 运行 进入以下错误。

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    The method inserter(File) in the type BatchInserters is not applicable for the arguments (String)

    at org.graphipedia.dataimport.neo4j.ImportGraph.<init>(ImportGraph.java:36)
    at org.graphipedia.dataimport.neo4j.ImportGraph.main(ImportGraph.java:48)

基于此 javadoc https://neo4j.com/docs/java-reference/current/javadocs/org/neo4j/unsafe/batchinsert/BatchInserters.html

BatchInserters 需要一个文件,而不是 "path/to/dir" 字符串。您将需要创建一个文件对象并将其传入。

代码: 在顶部添加导入。

import java.io.File

然后替换下面一行

inserter = BatchInserters.inserter(dataDir);

有了这个

inserter = BatchInserters.inserter(new File(dataDir));