Reputation: 429
I am attempting to parse an xml file referenced by a string using assetmanager, I have had a lot of help thanks to SO and this is what I have so far.
Document doc = db.parse(assetManager.open(Resources.getSystem().getString(R.string.FileName)));
String filename is my questions.xml file, I'm doing this so ultimately I can enforce localization on my app for multiple xml files. However my app is not able to read R.string.FileName, and errors out the application. Can anyone help me out here?
Upvotes: 0
Views: 312
Reputation: 67502
Resources.getSystem()
reads only system resources (android.R.x.x
).
If your code is in an Activity
, use the following:
String fname = getResources().getString(R.string.FileName);
Document doc = db.parse(assetManager.open(fname));
Otherwise, use this:
String fname = context.getResources().getString(R.string.FileName); // `context` is a Context object which you need to pass to this.
Document doc = db.parse(assetManager.open(fname));
Upvotes: 4