Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7192105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:52:17+00:00 2026-05-28T19:52:17+00:00

This code runs perfectly on Java but when I run this on Android platform,

  • 0

This code runs perfectly on Java but when I run this on Android platform, it throws TransformerException and FileNotFoundException. Why is it throwing such exceptions? This had bugged me whole day long. The code is as follows:

    public void createXMLInstance() {
    try {
        docBuilder = dbfac.newDocumentBuilder();
        document = docBuilder.newDocument();
        createSampleSMS();
        createDocumentTree();
        printToFile();
        System.out.println("Sample SmsML file generated");
    } catch (ParserConfigurationException pce) {
        pce.printStackTrace();
    }
}

private void createDocumentTree() {
    Element rootEle = document.createElement("Messages");
    document.appendChild(rootEle);
    Iterator<SMS> it = smsList.iterator();
    while (it.hasNext()) {
        SMS msg = (SMS) it.next();
        Element msgEle = createMessageElement(msg);
        rootEle.appendChild(msgEle);
    }
}

private void printToFile() {
    try {
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        Transformer transformer = transformerFactory.newTransformer();
        DOMSource source = new DOMSource(document);
        StreamResult result = new StreamResult(new File("SmsML.xml"));
        transformer.transform(source, result);
    } catch (TransformerException te) {
        te.printStackTrace();
    }
}

private Element createMessageElement(SMS msg) {

    Element contactEle = document.createElement("Contact");
    contactEle.setAttribute("Number", msg.contactNumber);
    contactEle.setAttribute("Name", msg.sendersName);

    Element msgBodyEle = document.createElement("Message");
    msgBodyEle.setAttribute("Date", msg.getFormattedDate(msg.fullDate));
    msgBodyEle.setAttribute("Time", msg.getFormattedTime(msg.fullDate));
    Text messagDescrip = document.createTextNode(msg.messageBody);
    msgBodyEle.appendChild(messagDescrip);
    contactEle.appendChild(msgBodyEle);
    return contactEle;
}
public void createSampleSMS() {
    smsList.add(new SMS("079399877339", "Tomas", "this is a sample message"));
    smsList.add(new SMS("079398546339", "", "hey how are you Sushan"));
    smsList.add(new SMS("079395486339", "Lusan", "i'm glad that you came to see me"));
    smsList.add(new SMS("079898899556", "Lusan", "i'm not well today"));
    smsList.add(new SMS("078158656522", "Jhu", "he told me he was feeling blue"));
    smsList.add(new SMS("079398546339", "Lusan", "oh that's so sad"));
}

EDIT: Got this form printStackTrace():

01-30 23:08:35.466: I/global(8995): Default buffer size used in BufferedInputStream constructor. It would be better to be explicit if an 8k buffer is required.
01-30 23:08:52.856: W/System.err(8995): javax.xml.transform.TransformerException: java.io.FileNotFoundException: /SmsML.xml (Read-only file system)
01-30 23:08:52.916: W/System.err(8995):     at org.apache.xalan.transformer.TransformerIdentityImpl.createResultContentHandler(TransformerIdentityImpl.java:297)
01-30 23:08:52.956: W/System.err(8995):     at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:330)
01-30 23:08:52.986: W/System.err(8995):     at my.android.pack.SmsMLActivity.printToFile(SmsMLActivity.java:79)
01-30 23:08:53.026: W/System.err(8995):     at my.android.pack.SmsMLActivity.create(SmsMLActivity.java:58)
01-30 23:08:53.056: W/System.err(8995):     at my.android.pack.SmsMLActivity.onCreate(SmsMLActivity.java:48)
01-30 23:08:53.086: W/System.err(8995):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-30 23:08:53.117: W/System.err(8995):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
01-30 23:08:53.146: W/System.err(8995):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-30 23:08:53.176: W/System.err(8995):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-30 23:08:53.206: W/System.err(8995):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-30 23:08:53.237: W/System.err(8995):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-30 23:08:53.266: W/System.err(8995):     at android.os.Looper.loop(Looper.java:123)
01-30 23:08:53.296: W/System.err(8995):     at android.app.ActivityThread.main(ActivityThread.java:4627)
01-30 23:08:53.336: W/System.err(8995):     at java.lang.reflect.Method.invokeNative(Native Method)
01-30 23:08:53.376: W/System.err(8995):     at java.lang.reflect.Method.invoke(Method.java:521)
01-30 23:08:53.407: W/System.err(8995):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-30 23:08:53.446: W/System.err(8995):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-30 23:08:53.476: W/System.err(8995):     at dalvik.system.NativeStart.main(Native Method)
01-30 23:08:53.506: W/System.err(8995): Caused by: java.io.FileNotFoundException: /SmsML.xml (Read-only file system)
01-30 23:08:53.566: W/System.err(8995):     at org.apache.harmony.luni.platform.OSFileSystem.openImpl(Native Method)
01-30 23:08:53.596: W/System.err(8995):     at org.apache.harmony.luni.platform.OSFileSystem.open(OSFileSystem.java:152)
01-30 23:08:53.627: W/System.err(8995):     at java.io.FileOutputStream.<init>(FileOutputStream.java:97)
01-30 23:08:53.656: W/System.err(8995):     at java.io.FileOutputStream.<init>(FileOutputStream.java:168)
01-30 23:08:53.686: W/System.err(8995):     at java.io.FileOutputStream.<init>(FileOutputStream.java:147)
01-30 23:08:53.726: W/System.err(8995):     at org.apache.xalan.transformer.TransformerIdentityImpl.createResultContentHandler(TransformerIdentityImpl.java:287)
01-30 23:08:53.756: W/System.err(8995):     ... 17 more
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T19:52:18+00:00Added an answer on May 28, 2026 at 7:52 pm

    As the stack trace clearly explains:

    01-30 23:08:53.506: W/System.err(8995): Caused by: java.io.FileNotFoundException: /SmsML.xml (Read-only file system)
    

    You cannot read a file that does not exist.

    Your problem stems from this line:

    StreamResult result = new StreamResult(new File("SmsML.xml"));
    

    That is not how you work with local files in Android, and that assumes that you are trying to parse some file that you downloaded yourself elsewhere in the code.

    To learn more about the internal and external storage areas in Android, you can review this section of the documentation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code produces a FileNotFoundException, but ultimately runs without issue: void ReadXml() { XmlSerializer
Am trying to run a selenium suite using this code which runs perfectly on
i have this code than runs perfectly .. returns a true .. when tracing
I have this code in Python which runs perfectly well. What it does is
This code runs on my local RoR/Windows 7 (64-bit): sql = ActiveRecord::Base.connection() last_pk =
I have a python script the runs this code: strpath = sudo svnadmin create
This code in a GUI application compiles and runs: procedure TForm1.Button1Click(Sender: TObject); begin Self
Please check this code out it compiles and runs absolutely fine.. The question is
This piece of code compiles and runs as expected on GCC 3.x and 4.x:
I have some C++ source code with templates maybe like this - doxygen runs

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.