Reputation: 85
As a preface to this question, I should make it known that this is my first non-trivial Android project. I have a reasonable background in programming, but am new to the platform. I'm working on a friend's app, which has been built up by numerous other parties before it came into my hands. What it is is a foraging guide made up of pictures and all sorts of information regarding identification, uses, poisonous parts, and so on. Users don't insert any information of their own -- it's just a big searchable library, basically.
Here's my issue: Right now, all the information is coming from multiple XML files in res/raw/, corresponding to different categories of information (ie: Plants, Recipes). There's an XML parser that's been implemented, ostensibly to read the contents of the XML files and then populate lists of objects corresponding to the aforementioned categories. Each category is defined in a class of its own, and there are 6 such categories.
My job is to change all this over to read from a SQLite database, which my friend has already created. Now each category corresponds to a table in the database, and the columns of the tables correspond to various bits of associated information. It all looks quite straightforward.
Using one of the many easy-to-follow tutorials online, I thought I'd been successful in basically replacing the XML parser with a database helper that worked by opening the DB and populating category lists with tuples from the tables. I felt like I wouldn't need to substantially modify other parts of the code in order for the data source switchover to work.
I thought it worked because I removed the XML parser, and it compiled and produced the same result on my test device. However, I realized I was wrong -- when I removed res/raw/, the app crashes. After re-cloning the project to check, it in fact seems that the XML parser isn't even needed at all for the XML data to be read perfectly well into the program! So I'm obviously missing something important with regard to where/how this XML data is being integrated into the app. The XML gets read in whether or not the parser is present, but if the XML files are removed, the app crashes.
It looks like it should be so easy to just dump tuples in as objects on a list and then let the existing code deal with them as they do. That would let me avoid substantially reworking the rest of the code, as it intuitively seems unnecessary.
Can anyone explain a bit about how the XML resources are working, and why the app runs just fine without the parser? Like I said, I'm shy of messing around too much with what's already in place. Basically I need some suggestions on a strategy for carrying this out, but haven't been able to find anything.
Thank you so much for any help you can give me.
Upvotes: 0
Views: 101
Reputation: 3574
If I understand correctly, when the app starts it populates database from the xml files. If so, when you delete the files and start app it should crush since there are no files anymore.
What you can do is prepopulate database file from xml files in some other script/program. Then copy the database file into assests
folder. Now you will not need xml files (so just delete them) and use your db file.
Upvotes: 1