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

  • SEARCH
  • Home
  • 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 3792646
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:39:16+00:00 2026-05-19T12:39:16+00:00

I have this strange crash I can’t figure out. The first time I launch

  • 0

I have this strange crash I can’t figure out.

The first time I launch the app I check if /data/Message.xml exists. If not I create one.
I then navigate to a page where I parse that xml file and it crashes because it doesn’t exist (so it didn’t create one). I looked in the data directory and indeed, it didn’t create one.

Then I launch the app again and it executes the same code, while this time it DOES create the xml file.

I don’t know why it isn’t working the 1st time, the app doesn’t change anything untill it crashes on the first time and the conditions are the same when it launches for the 2nd time.

Is it an Android thing?


More detailed information:

I check if the file is available:

File file = new File(Environment.getDataDirectory() + "/data/com.name.app/files/Message.xml");

if (file.exists() == false) {
createFirstXML();
}

createFirstXML():

public void createFirstXML() {

File newxmlfile = new File(Environment.getDataDirectory() + “/data/com.name.app/files/Message.xml”);
try {
newxmlfile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
FileOutputStream fileos = null;
try {
fileos = new FileOutputStream(newxmlfile);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
XmlSerializer serializer = android.util.Xml.newSerializer();
try {
serializer.setOutput(fileos, “UTF-8”);
serializer.startDocument(null, Boolean.valueOf(true));
serializer.setFeature(“http://xmlpull.org/v1/doc/features.html#indent-output”, true);

serializer.startTag(null, “Message”);

serializer.startTag(null, “Service”);
serializer.text(“App”);
serializer.endTag(null, “Service”);

serializer.endTag(null, “Message”);

serializer.endDocument();
serializer.flush();
fileos.close();
} catch (Exception e) {
e.printStackTrace();
}
}

The log:

java.io.IOException: No such file or directory
 bla
 bla
java.io.FileNotFoundException: /data/data/com.name.app/files/Message.xml (No such file or directory)
 bla
 bla
java.lang.IllegalArgumentException
 bla
 bla
java.io.FileNotFoundException: /data/data/com.name.app/files/Message.xml (No such file or directory)
 bla
 bla
java.io.FileNotFoundException: /data/data/com.name.app/files/Message.xml (No such file or directory)
 bla
 bla

The second time I launch my app it also can’t find Message.xml (because it executes createFirstXML();) but it doesn’t give the exceptions???

I really don’t get it..

  • 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-19T12:39:17+00:00Added an answer on May 19, 2026 at 12:39 pm

    First of all, getDataDirectory probably isn’t what you want. It (currently) returns the top level directory where packages are installed, hence when you append “/data/com.themobilecompany.sosinternational/files/Message.xml” to it, you get “/data/data/com.themobilecompany.sosinternational/files/Message.xml”. See your exception info:

    java.io.FileNotFoundException: /data/data/com.themobilecompany.sosinternational/files/Message.xml (No such file or directory)

    This directory doesn’t exist which is why you’re getting the exception and are never able to open the file.

    Better to use getFilesDir() which will return the private file location for your app and will therefore be compatible with future Android versions that may change the filesystem layout.

    getFilesDir will currently return “/data/com.themobilecompany.sosinternational/” so try changing

    File newxmlfile = new File(Environment.getDataDirectory() + "/data/com.themobilecompany.sosinternational/files/Message.xml");

    to

    File newxmlfile = new File(Context.getFilesDirectory() + "/files/Message.xml");

    Don’t forget to create the files directory if it does not already exist.

    Do you run this code in your onCreate, or is it triggered by your onCreate or something similar? If so, the normal activity lifecycle will mean that your code is not run every time you start your app. onCreate will be called when your activity is created, most of the time, when you “exit” (i.e. press the back button), you are just suspending your activity. When you restart it Android simply reuses the existing suspended activity so your onCreate will not be called on what appear to be subsequent executions of your app – hence why the exception does not always occur.

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

Sidebar

Related Questions

I have a problem with a strange crash on iPad 5.0. This crash only
Can anyone tell me why I always have this strange output after running this
I have another strange bug which I cannot figure out. I try to create
I have this strange crash relating to ARC auto-inserting objc_retains in my code. I
I have this strange behavior in my JSP page: I have two Integer variables
I have this strange problem. I am retrieving twitters and it works on the
I have this strange error, When I call $element_attrs = $element -> attributes(); I
i have this strange problem with the PHP function CTYPE_ALNUM if i do: PHP:
Starting from Android 3.2 I have this strange problem. It's very easy to reproduce:
So i have this rather strange issue, i am trying to line up some

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.