My current work needs to do the development based on open soure software. There is a class defined as DirLocator.java The code is as follows

public final class DirLocator implements IResourceLocator
{
    /** The folder relative to which resources are resolved. */
    private File dir;

    /**
     * Initializes the locator using the given directory. If the argument is null or a
     * non-existent folder, the locator will return an empty set of resources.
     */
    public DirLocator(File dir)
    {
        this.dir = dir;
    }

    /**
     * Initializes the locator using the given path. If the argument is null or a
     * non-existent folder, the locator will return an empty set of resources.
     */
    public DirLocator(String dirPath)
    {
        this(dirPath == null ? null : new File(dirPath));
    }

    /**
     *
     */
    @Override
    public IResource [] getAll(String resource)
    {
        if (dir != null && dir.isDirectory() && dir.canRead())
        {
            resource = resource.replace('/', File.separatorChar);
            while (resource.startsWith(File.separator))
            {
                resource = resource.substring(1);
            }

            final File resourceFile = new File(dir, resource);
            if (resourceFile.isFile() && resourceFile.canRead())
            {
                return new IResource []
                {
                    new FileResource(resourceFile)
                };
            }
        }
        return new IResource [0];
    }
    
    @Override
    public int hashCode()
    {
        return ObjectUtils.hashCode(dir);
    }

    @Override
    public boolean equals(Object target)
    {
        if (target == this) return true;

        if (target != null && target instanceof DirLocator)
        {
            return ObjectUtils.equals(this.dir, ((DirLocator) target).dir);
        }

        return false;
    }

    @Override
    public String toString()
    {
        return this.getClass().getName() + " [dir: "
            + (dir == null ? "null" : dir.getAbsolutePath()) + "]";
    }
}

I create an object as follows

File lexicalDir = new File("resources");
         ResourceLookup lexicalResourceLookup = new ResourceLookup(new DirLocator(lexicalDir));

But the compiler says "The constructor DirLocator(File) is undefined"

I do not know where is the error come from, and how to fix it? If you need more information, please let me know.

Post the actual stack trace. And I hope the class containing this call does not import a class named "File" (or that its package does not contain a class named "File") that is different from the "File" imported in DirLocator (or from a class named File in its package).

The error message was just given by Eclipse without even compiling the code. So there is no stack trace. Do you nee me to post the java file containing
ResourceLookup lexicalResourceLookup = new ResourceLookup(new DirLocator(lexicalDir));

In fact, I constructed ResourceLookup this way based on an example given in the software. I do not understand why the system does not allow me to do the same thing. Thanks.

Post the actual stack trace. And I hope the class containing this call does not import a class named "File" (or that its package does not contain a class named "File") that is different from the "File" imported in DirLocator (or from a class named File in its package).

Post the import statements for your class.

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;
import java.util.Vector;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.lucene.store.FSDirectory;
import org.carrot2.clustering.lingo.LingoClusteringAlgorithm;
import org.carrot2.clustering.stc.STCClusteringAlgorithm;
import org.carrot2.core.Controller;
import org.carrot2.core.ControllerFactory;
import org.carrot2.core.IClusteringAlgorithm;
import org.carrot2.core.IDocumentSource;
import org.carrot2.core.ProcessingComponentConfiguration;
import org.carrot2.core.ProcessingResult;
import org.carrot2.core.attribute.AttributeNames;
import org.carrot2.source.lucene.LuceneDocumentSource;
import org.carrot2.source.lucene.SimpleFieldMapper;
import org.carrot2.util.attribute.AttributeUtils;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.carrot2.text.linguistic.DefaultLexicalDataFactoryDescriptor;
import org.carrot2.util.resource.ContextClassLoaderLocator;
import org.carrot2.util.resource.DirLocator;
import org.carrot2.util.resource.FileResource;
import org.carrot2.util.resource.IResource;
import org.carrot2.util.resource.ResourceLookup;

import com.carrotsearch.lingo3g.Lingo3GClusteringAlgorithm;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

Post the import statements for your class.

That all looks reasonable to me. Assuming you don't have any custom classes named File or DirLocator within that same package, I would wonder if some other issue is preventing the Eclipse parser from correctly seeing that constructor. It's obviously there and is public.

Is it possible that you have included an old version of the Carrot2 jar? Because the archived 2.x version API does not have that constructor for DirLocator. It only has the DirLocator(String) constructor.

Yes, that was the issue. Thanks.

Is it possible that you have included an old version of the Carrot2 jar? Because the archived 2.x version API does not have that constructor for DirLocator. It only has the DirLocator(String) constructor.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.