Reputation: 4897
I have spent quite a while trying to solve this problem, but to no avail. I have searched stackoverflow as well as Google and have not been able to resolve my (seemingly) simple problem.
I am getting a FileNotFoundException in the following line:
Image.FromFile("\\Resources\\Icons\\key-icon.png");
The folders and image are really there, and I can't see what the problem is.
Upvotes: 3
Views: 10082
Reputation: 21
For this case I discovered that sikuli does not automatically detect the root folder of the project. What you should do for this case is specify the folder using the command System.getProperty("user.dir");
import org.sikuli.script.*;
public class Test {
public static void main(String[] args) {
Screen s = new Screen();
try{
String pathYourSystem = System.getProperty("user.dir") + "\\";
s.click(pathYourSystem + "imgs/spotlight.png");
//s.wait(pathYourSystem + "imgs/spotlight-input.png");
//s.click();
s.write("hello world#ENTER.");
}
catch(FindFailed e){
e.printStackTrace();
}
}
}
Upvotes: 0
Reputation: 973
Image.FromFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
@"Resources\\Icons\\key-icon.png"))
Base-directory Combine your file-name
Upvotes: 1
Reputation: 32134
Internally, Image.FromFile
uses File.Exists
to check whether the file exists. This method returns false
when:
It may be that the second option is your problem.
And another possibility: is Resources
a network share? In that case you should use the following:
Image.FromFile("\\\\Resources\\Icons\\key-icon.png");
Upvotes: 0
Reputation: 1459
You should consider that it is started from "yourproject/bin/Release" so you need to go up 2 directories. Do this:
Image.FromFile("..\\..\\Resources\\Icons\\key-icon.png");
Upvotes: 11
Reputation: 9725
Try using an absolute path not a relative one... i.e.
Image.FromFile(Server.MapPath(@"~\Resources\Icons\key-icon.png"));
Upvotes: 4
Reputation: 4554
You may be missing a leading ".":
Image.FromFile(".\\Resources\\Icons\\key-icon.png");
Upvotes: 0