Hello i'm new to android and in my application i want to get some data from an XML file..but it gives an error saying file not found error..Can anyone tell me how to correctly ponit to a file in android.Thanx in advance.
Exception:-
09-18 12:24:19.889: WARN/System.err(2550): java.io.FileNotFoundExceptio开发者_运维百科n: /res/xml/persons.xml (No such file or directory)
Content stored within the /res/ folder is not within the regular filesystem. You need to access it from the resources. Call getResources
from your activity, and you can see the functions there to operate on resources. Depending on what are you calling, there may already be an overload that takes a resource id already. Note that it might make more sense to move your xml to the /raw/ folder instead of /xml/.
You can open an InputStream to your resource file like this:
InputStream is = context.getResources().openRawResource(R.xml.persons);
'context' would generaly be your activity.
精彩评论