android - cannot resolve getAssets() method -
hi have been having trouble getasset() method. trying xml file assets folder getasset() put inputstream.
code:
public class mainactivity extends appcompatactivity { list people; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); try { inputstream = getassets().open("people.xml"); people = xmlparser.readpeople(is); }catch (ioexception e){ e.printstacktrace(); } } }
xml:
<people> <person> <name>joe</name> <dob>11/08/16</dob> <gender>male</gender> </person> </people>
can tell me going on getassets() method
instead of this
try { inputstream = getassets().open("people.xml"); people = xmlparser.readpeople(is); }catch (ioexception e){ e.printstacktrace(); }
use
try { assetmanager assetmanager = getbasecontext().getassets(); inputstream = assetmanager.open("people.xml"); people = xmlparser.readpeople(is); }catch (ioexception e){ e.printstacktrace(); }
Comments
Post a Comment