InputSource not working in Android while retrieving data from Assets?



After checking the answers from the other questions and applying them to my program, I still have problems loading assets from my Project.


Here is the block of code which has the problem and it seems to not go past the line with the comment //BUG



public void parseXmlFile(String xml_file, String object, String xml_class, String pointer, Activity activity, TextView test) throws ParserConfigurationException, SAXException, IOException{

view = test;

view.setText("2.1");
categories_list = new ArrayList<Category>();

//instantiate String object sto be used throughout class
object_name = object;
class_type = xml_class;
value_pointer = pointer;


//get factory
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();


//get instance of document builder to build document from xml file
DocumentBuilder builder = factory.newDocumentBuilder();



//Create bytestream which allows a stream of data from xml to document builder
ByteArrayInputStream byte_stream = new ByteArrayInputStream(xml_file.getBytes("utf-8"));


//create an input source for the bytestream
InputSource input_src = new InputSource(activity.getAssets().open(xml_file));

dom = builder.parse(input_src); //BUG

parseDocument();

byte_stream.close();
}


My XML is in the assets folder and the app doesn't crash, it just doesn't do anything. The response i'm supposed to get is a listview of buttons gotten from the parsing of the XML. The algorithm to parse the XML works as it has been tested in a normal Java application. I just want to apply it to the Android app.


If you want more info just comment.


No comments:

Post a Comment