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 8933813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:38:06+00:00 2026-06-15T09:38:06+00:00

I’m making an app that creates new files, there’s no problem when I name

  • 0

I’m making an app that creates new files, there’s no problem when I name the files like this:

private String FILENAME = "myFilename";

but when I use a method to name the file, the compiler jumps straight to this line:

String lineSep = System.getProperty("line.separator");

then to my class declaration:

public class AddUser extends Activity

And the application crashes.

This is what the log file says:

12-03 16:26:12.814: E/AndroidRuntime(20307): FATAL EXCEPTION: main
12-03 16:26:12.814: E/AndroidRuntime(20307): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp.app/com.myapp.app.ProfileSaved}: java.lang.NullPointerException
12-03 16:26:12.814: E/AndroidRuntime(20307):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
12-03 16:26:12.814: E/AndroidRuntime(20307):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
12-03 16:26:12.814: E/AndroidRuntime(20307):    at android.app.ActivityThread.access$600(ActivityThread.java:130)

This is my file naming method:

int firstArray;
int nextArray;  

private String fileNamer(){

    File dataDirectory = Environment.getDataDirectory();
    File fileDir = new File(dataDirectory, "data/com.myapp.app/files");

    String[] filenameArray = fileDir.list();

    Arrays.sort(filenameArray);

    if (filenameArray.length == 0){
        return "0";
    }

    if (filenameArray.length == 2500){
        return "too_many_items";
    }

    if (!filenameArray[0].equals("0")){
        return "0";
    }

    int arrayLength = filenameArray.length;
    int i;

    for(i=0; i<arrayLength-1;){

        firstArray = Integer.parseInt(filenameArray[i]);
        nextArray = Integer.parseInt(filenameArray[i+1]);

        if (firstArray+1 == nextArray){
            i++;
        }
    }
    return Integer.toString(nextArray+1);
}

The method seems to be working fine but I just can’t see why would it affect the rest of the program since all it does is to return a String?

  • 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-06-15T09:38:07+00:00Added an answer on June 15, 2026 at 9:38 am

    Ok guys thanks for your input.

    I believe I finally got it right. First of all the method indeed was buggy but that wasn’t really the issue, a good answer would’ve been something like:

    “There IS a difference between a String and invoking a method that returns a String that is assigned to a variable, because in order to use the invoked String in another Class you’ll probably need to set the variable as static. That’s why the String is working and the ‘method invoked’ String not.”

    About the bugs in the code just in case someone is ever interested, the if in

    if (firstArray+1 == nextArray) 
    

    needs the else in case there is an empty space between filenames, like 1, 3, 4 so the next file gets named 2.

    The other bug was that I was comparing filenames as Strings so when I sorted them, they were sorted as 1, 10, 2, 3, 4, 5, 6, 7, 8, 9.

    The solution I used was to add zeros to the beginning of the filenames like 0001, 0002, and so on.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I would like to count the length of a string with PHP. The string
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but

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.