I am making a simple android application and I am having issues parsing a simple XML file. I get the FileNotFoundException even through the file exists and I have all the permissions for it. I tried to modify the path in all the possible ways but I always get this exception thrown.
here's my code in the main activity:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Engine engine = new Engine();
engine.parse();
}
in the engine class:
public void parse() {
try {
File fXmlFile = new File("/res/XML/users.xml");
if (!fXmlFile.exists()) {
throw new FileNotFoundException("Failed to find file: " +
fXmlFile.getAbsolutePath());
}
DocumentBuilderFactory dbFactory = DocumentBuilderFactory
.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fXmlFile);
...
it really looks simple but I can't get this to work. any idea of what I'm doing wrong?