I'm a beginning developer for Android and running into the following problem when trying to access an XML file on the SD card.
To start, I performed the following checks: - Permission to read/write external storage is given in android manifest - The file exists in the specified location - I checked: fileexists = true; canread = true; isfile = true - externalstorage state = mounted
Still the FileInputStream gives me the FileNoteFoundException. The code:
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
//probeersel
public void myClickHandler(View view) {
switch (view.getId()) {
case R.id.button1:
XPath xpath = XPathFactory.newInstance().newXPath();
File mealsource = new File(getExternalFilesDir(null)
+ "/test.xml");
Toast.makeText(this, "External Files Dir: " + getExternalFilesDir(null), Toast.LENGTH_LONG).show();
Toast.makeText(this, "Exists: " + String.valueOf(mealsource.exists()), Toast.LENGTH_LONG).show();
Toast.makeText(this, "Can read: " + String.valueOf(mealsource.canRead()), Toast.LENGTH_LONG).show();
Toast.makeText(this, "Is file: " + String.valueOf(mealsource.isFile()), Toast.LENGTH_LONG).show();
Toast.makeText(this, "External Storage State: " + Environment.getExternalStorageState(), Toast.LENGTH_LONG).show();
Toast.makeText(this, "Absolute path " + mealsource.getAbsolutePath(), Toast.LENGTH_LONG).show();
FileInputStream mealstream = new FileInputStream(mealsource);
InputSource inputsource = new InputSource(mealstream);
expression = "Meals/Meal/ShrtDesc/text()";
meallist = (NodeList) xpath.evaluate(expression, inputsource, XPathConstants.NODE);
etc
So to recap: All my checks say the file is there to be read and ready for action, but the FileInputStream constructor seems blind to it. What am I to do? What have I missed? Could it have to do with the content of the xml somehow?
Thanks a lot for any help or pointers you can give me.