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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:08:03+00:00 2026-06-06T01:08:03+00:00

I’m having a bizarre problem and I’m not sure if I’m doing something wrong

  • 0

I’m having a bizarre problem and I’m not sure if I’m doing something wrong or something.
For some reason, my AsyncTask won’t call doInBackground but it calls onPostExecute(). It’s essential that this AsyncTask gets called because it initializes a variable I will need throughout the rest of the app.

I have a nested class in my main activity that extends AsyncTask. This class takes care of downloading file names from the user’s Dropbox account:

protected class FilesLister extends AsyncTask<String, Integer, Long>
{
    @Override
    protected Long doInBackground(String... params)
    {
        Log.i("Entries", "We believe Entries has some values now.");
        ArrayList<Entry> theFiles = new ArrayList<Entry>();
        try
        {
            Entry entries = mDBApi.metadata("/", 20000, null, true, null);
            for (Entry e : entries.contents)
            {
                Log.i("Hm", e.fileName());
                if (!e.isDeleted)
                {
                    if(!e.isDir)
                    {
                        theFiles.add(e);
                    }
                }
            }
            theEntries = theFiles.toArray(new Entry[theFiles.size()]);
        } catch (DropboxException e1)
        {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        return null;
    }

    protected void onPostExecute(Long result)
    {
        super.onPostExecute(result);
        Log.i("Now", "Calling refresh.");
        refresh();
    }
}

Like you can see, onPostExecute calls a method called refresh(). refresh() is implemented as follows:

public void refresh()
{
    //Sort all this files by last modified date.
    Arrays.sort(theEntries, new Comparator<Entry>()
    {
        @Override
        public int compare(Entry firstFile, Entry secondFile)
        {
            //"EEE, dd MMM yyyy kk:mm:ss ZZZZZ"
            SimpleDateFormat formater = new SimpleDateFormat("EEE, dd MMM yyyy kk:mm:ss ZZZZZ");
            try
            {
                Date date1 = (Date)formater.parse(firstFile.modified);
                Date date2 = (Date)formater.parse(secondFile.modified);
                return date1.compareTo(date2);
            } catch (ParseException e1)
            {
                e1.printStackTrace();
            }
            return 0;
        }
    });
    //Now we create a String[] array to hold the names of all the fetched files...
    ArrayList<String>txtFilesNames = new ArrayList<String>();
    for(int i = theEntries.length - 1; i >= 0; i--)
    {
        //Loops goes from top to bottom so the latest file appears at the top of the ListView.
        txtFilesNames.add(theEntries[i].fileName());
    }
    actualFileNames = txtFilesNames.toArray(new String[txtFilesNames.size()]);
    ArrayAdapter<String> ad = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, actualFileNames);
    lv.setAdapter(ad);
}

I know refresh() is being called for two reasons: LogCat logs “Calling refresh.” and then the app crashes because of a NullPointerException. The null pointer exceptions is thrown because theEntries is indeed null, and it will be null unless doInBackground() gets called. And I know doInBackground is never called due to the null pointer and because the Log I put on it’s body never gets called. So what could cause my doInBackground() method not to get called? If it matters, I execute the AsyncTask in my onResume method, and I don’t execute any other AsyncTasks in either onCreate or onStart.

  • 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-06T01:08:05+00:00Added an answer on June 6, 2026 at 1:08 am

    Are you sure doInBackground isn’t getting called? There are plenty of other ways which could cause theEntries to be null. For instance, an exception here:

            Entry entries = mDBApi.metadata("/", 20000, null, true, null);
            for (Entry e : entries.contents)
            {
                Log.i("Hm", e.fileName());
                if (!e.isDeleted)
                {
                    if(!e.isDir)
                    {
                        theFiles.add(e);
                    }
                }
            }
    

    could cause theEntries to be null. Also, I think you could do this a better way. Instead of setting theEntries within doInBackground (which is in a different thread than your object was created in) you should instead have that function return the entries which will pass them to onPostExecute.I believe the code would look like this:

    protected class FilesLister extends AsyncTask<String, Integer, Entry[]>
    {
        @Override
        protected Entry[] doInBackground(String... params)
        {
            Log.i("Entries", "We believe Entries has some values now.");
            Entry[] entriesReturn = null;
            ArrayList<Entry> theFiles = new ArrayList<Entry>();
            try
            {
                Entry entries = mDBApi.metadata("/", 20000, null, true, null);
                for (Entry e : entries.contents)
                {
                    Log.i("Hm", e.fileName());
                    if (!e.isDeleted)
                    {
                        if(!e.isDir)
                        {
                            theFiles.add(e);
                        }
                    }
                }
                entriesReturn = theFiles.toArray(new Entry[theFiles.size()]);
            } catch (DropboxException e1)
            {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            return entriesReturn;
        }
    
        protected void onPostExecute(Entry[] result)
        {
            super.onPostExecute(result);
            Log.i("Now", "Calling refresh.");
            refresh(result);
        }
    }
    

    Then in your refresh method do the assignment.. Also you should check for null in the refresh method.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I am currently running into a problem where an element is coming back from
I need a function that will clean a strings' special characters. I do NOT

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.