Note that there are some explanatory texts on larger screens.

plurals
  1. PO malformed url exception:protocol not found while adding or deleting data from xml in android?
    primarykey
    data
    text
    <p>I have given the sample of an xml I am using to get the list of food items and inflating it to the list view.while I try to add the item to my xml file at runtime I am getting url malformed exception.may be the path I am giving is not valid.I have put my xml in package/res/raw/testcalory.xml.kindly help.</p> <p>EXCEPTION:12-26 14:35:58.516: WARN/System.err(11597): java.net.MalformedURLException: Protocol not found: testcalory.xml</p> <pre><code>//sample xml &lt;?xml version="1.0"?&gt; &lt;company&gt; &lt;Row&gt; &lt;Item_Name&gt;Aam Ras &lt;/Item_Name&gt; &lt;CalorieContentPerGram&gt;1.12&lt;/CalorieContentPerGram&gt; &lt;/Row&gt; &lt;Row&gt; &lt;Item_Name&gt;Akuri &lt;/Item_Name&gt; &lt;CalorieContentPerGram&gt;1.62&lt;/CalorieContentPerGram&gt; &lt;/Row&gt; &lt;Row&gt; &lt;Item_Name&gt;Almond ICC &lt;/Item_Name&gt; &lt;CalorieContentPerGram&gt;5.35&lt;/CalorieContentPerGram&gt; &lt;/Row&gt; &lt;Row&gt; &lt;Item_Name&gt;Almond Milkshake &lt;/Item_Name&gt; &lt;CalorieContentPerGram&gt;1.16&lt;/CalorieContentPerGram&gt; &lt;/Row&gt; &lt;/company&gt; //sample code private void addItem() { // TODO Auto-generated method stub try{ FileOutputStream fOut = openFileOutput("testcalory", MODE_WORLD_READABLE); OutputStreamWriter osw = new OutputStreamWriter(fOut); String filepath = "testcalory.xml"; DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); Document doc = docBuilder.parse(filepath); org.w3c.dom.Element Row; org.w3c.dom.Element Item_Name; org.w3c.dom.Element CalorieContentPerGram; Node company = doc.getElementsByTagName("company").item(0); Row=doc.createElement("Row"); Item_Name=doc.createElement("Item_Name"); Item_Name.appendChild(doc.createTextNode("hulala")); Row.appendChild(Item_Name); CalorieContentPerGram=doc.createElement("CalorieContentPerGram"); CalorieContentPerGram.appendChild(doc.createTextNode("556")); Row.appendChild(CalorieContentPerGram); company.appendChild(Row); //write the content into xml file TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); DOMSource source = new DOMSource(doc); StreamResult result = new StreamResult(new File(filepath)); transformer.transform(source, result); result.setWriter(osw); osw.flush(); osw.close(); }catch(ParserConfigurationException pce){ pce.printStackTrace(); }catch(TransformerException tfe){ tfe.printStackTrace(); }catch(IOException ioe){ ioe.printStackTrace(); }catch(SAXException sae){ sae.printStackTrace(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload