Question

I'm using eclipse, my code: -

package arrowRecog;

import org.sikuli.api.*;
import java.io.File;
import arrowRecog.res.*;

public class FocusTrain
{
    public static void main(String[] args) throws Exception
    {
         Target oneDown = new ImageTarget(new File("arrowRecog.res","1down.jpg"));
    }
}

The Tree:

http://i1316.photobucket.com/albums/t601/Preformer/tree_zps1e15285b.jpg

The Exception:

http://i1316.photobucket.com/albums/t601/Preformer/error_zps05bc7502.jpg

Was it helpful?

Solution 2

I have no idea why you put non-sourcecode resources into src directory. Directories here are interpreted by Eclipse as packages, so they are shown in the "folder.subfolder" format. The File class is using the filesystem, not java class path format, so "arrowRecog.res" will not be interpreted as "arrowRecog" directory with subdirectory "res", but it will be searching for "arrowRecog.res" directory - which does not exist. In other words, the dot will not be taken for path delimiter, but as part of the directory name.

Also, since you are using relative paths, that means relative to the working directory. The working directory is by default the main directory of the project in Eclipse (if I remember correctly). So you are missing the "src" dir in your paths.

new File("src/arrowRecog/res/1down.jpg")

or

new File("arrowRecog/res/1down.jpg")

should probably work, depending on how your working directory is set.

The best thing to do is create a new directory next to the src directory (called res for example) and all images move there.

OTHER TIPS

The problem is the "\1" part of the string literal. That's not a backslash followed by a 1 - that's an octal escape sequence, yielding U+0001. To get the string you were aiming for, you want:

Target oneDown = new ImageTarget(new File("arrowRecog.res\\1down.jpg"));

Or better - more portable:

Target oneDown = new ImageTarget(new File("arrowRecog.res/1down.jpg"));

Or even better:

Target oneDown = new ImageTarget(new File("arrowRecog.res", "1down.jpg"));

(In practice, every platform I've used Java on has coped with / as a directory separator, but using the File constructor taking two strings is still a good idea in general.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top