visionz510
New Member
I am working off of this example in which the author pulls+parses an xml file via HTTP request. I am attempting to manipulate this project to instead load the same xml from the assets folder. When I load it however I am getting a Null Pointer. I am passing context as I believe I should in addition to loading the "url" from the assets folder. Where is my error in this code? MainActivity snippet-initializing url string and calling getXML\[code\] static final String URL = "file:///android_asset/sample.xml"; @Overridepublic void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ... XMLParser parser = new XMLParser(); String xml = parser.getXmlFromUrl(URL, context); // getting XML ... }\[/code\]XMLParser Class' method:\[code\] public String getXmlFromUrl(String URL, Context context){ String xml = null; AssetManager am = context.getAssets(); try { InputStream is = am.open(URL); int length = is.available(); byte[] data = http://stackoverflow.com/questions/12500100/new byte[length]; is.read(data); xml = new String(data); } catch (IOException e1) { e1.printStackTrace(); } return xml;}\[/code\]