Inco Mob
Inco Mob

Reputation: 594

Point to an XML file in android

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.FileNotFoundException: /res/xml/persons.xml (No such file or directory)

Upvotes: 1

Views: 256

Answers (1)

K-ballo
K-ballo

Reputation: 81349

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.

Upvotes: 2

Related Questions