Hi Dancing,
First u check, whether ur xml file s created or not. my guess is
there s some problem in save xml because of that u r getting null
pointer exception.
and for writing u hav to give permission in ur Manifest.xml file
Moktarul anam
On Feb 27, 9:27 pm, Dancing Fingers <[email protected]> wrote:
> Hi guys,
> My app needs to learn user words and store them in XML files. So I
> wrote a test method:
>
> public void writeWordXmlFile() {
> myWords = new ArrayList<Word>();
> myWords.add(new Word("Diversability"));
> myWords.add(new Word("Theate"));
>
> try {
> FileOutputStream fos = new
> FileOutputStream("mywords.xml");
> XmlSerializer serializer = Xml.newSerializer();
> serializer.setOutput(fos, "UTF-8");
> serializer.startDocument(null,
> Boolean.valueOf(true));
> //set indentation option
> serializer.setFeature("http://xmlpull.org/v1/
> doc/features.html#indent-output", true);
> serializer.startTag("", "Words");
>
> for( int i=0; i<myWords.size(); i++) {
> serializer.startTag("", "WordPair");
>
> serializer.startTag("", "word");
> serializer.text(myWords.get(i).getWord());
> serializer.endTag("", "word");
> serializer.startTag("", "count");
>
> serializer.text(Integer.toString(myWords.get(i).getCount()));
> serializer.endTag("", "count");
>
> serializer.endTag("", "WordPair");
> }
> serializer.endTag("", "Words");
> fos.close();
> System.out.println("mywords.xml file written.");
> } catch (IOException e) {
> System.out.println(e);
> }
> }
>
> This appears to work fine. So I wrote a SAX Xml parser and I kept
> getting a File Not Found exception. So a wrote a simple file reader
> method :
>
> public void parseMyWordXmlFile() {
> myWords = new ArrayList<Word>();
> Word wHandler = new Word();
> String sIn;
> //create an InputSource from the XML document source
> try {
> System.out.println("Reading mywords.xml");
> BufferedReader bin = new BufferedReader( new
> FileReader( "mywords.xml"));
> while ((sIn = bin.readLine()) != null){
> System.out.println(sIn);
> }
> } catch (Exception e) {
> System.out.println("NOT Reading mywords.xml" + e);
> }
> }
>
> Again, I get a FileNotFound Exception. Doesn't Android read and write
> to the same path in internal memory?
>
> Thanks.
> Chris
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en