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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:24:12+00:00 2026-06-02T02:24:12+00:00

I’m using AsyncTask to get all the data my app needs from a server.

  • 0

I’m using AsyncTask to get all the data my app needs from a server. This works fine. However, when restarting the application for the second time, the app crashes.

I get the following errorlog:

04-17 14:22:57.171: E/AndroidRuntime(956): FATAL EXCEPTION: AsyncTask #2
04-17 14:22:57.171: E/AndroidRuntime(956): java.lang.RuntimeException: An error occured while executing doInBackground()
04-17 14:22:57.171: E/AndroidRuntime(956):  at android.os.AsyncTask$3.done(AsyncTask.java:278)
04-17 14:22:57.171: E/AndroidRuntime(956):  at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
04-17 14:22:57.171: E/AndroidRuntime(956):  at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
04-17 14:22:57.171: E/AndroidRuntime(956):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
04-17 14:22:57.171: E/AndroidRuntime(956):  at java.util.concurrent.FutureTask.run(FutureTask.java:137)
04-17 14:22:57.171: E/AndroidRuntime(956):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
04-17 14:22:57.171: E/AndroidRuntime(956):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569) 
04-17 14:22:57.171: E/AndroidRuntime(956):  at java.lang.Thread.run(Thread.java:856)
04-17 14:22:57.171: E/AndroidRuntime(956): Caused by: java.lang.ArrayIndexOutOfBoundsException: length=14; index=14
04-17 14:22:57.171: E/AndroidRuntime(956):  at flexform.ro.android.app.FlexFormActivity$getDataClass.doInBackground(FlexFormActivity.java:88) 
04-17 14:22:57.171: E/AndroidRuntime(956):  at flexform.ro.android.app.FlexFormActivity$getDataClass.doInBackground(FlexFormActivity.java:1)
04-17 14:22:57.171: E/AndroidRuntime(956):  at android.os.AsyncTask$2.call(AsyncTask.java:264)
04-17 14:22:57.171: E/AndroidRuntime(956):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)

Below you have my asynctask class:

class getDataClass extends AsyncTask<String, Void, String>{
    protected String doInBackground(String...urls){
        String response = "";
        for(String url : urls){
            response = "";
            descriptionArray_Counter++;

            DefaultHttpClient client = new DefaultHttpClient();
            HttpGet httpGet = new HttpGet(url);
            try{
                HttpResponse execute = client.execute(httpGet);
                InputStream content = execute.getEntity().getContent();

                BufferedReader buffer = new BufferedReader(new InputStreamReader(content));

                String s = "";

                while((s = buffer.readLine()) != null){
                    response += s;
                }
            }catch(Exception e){
                e.printStackTrace();
            }
            Resources.descriptionArray[descriptionArray_Counter] = response;
        }
        return response;
    }

    protected void onPostExecute(String result){
        Toast.makeText(getApplicationContext(), "All entres have been loaded!", Toast.LENGTH_SHORT).show();

        JSONArray offersJSON;
        JSONArray newsJSON;

        try{
            newsJSON = new JSONArray(Resources.descriptionArray[9]);

            if(newsJSON.length() > 20)
                Resources.newsLength = 20;
            else
                Resources.newsLength = newsJSON.length();

            for(int i = 0; i < Resources.newsLength; i++){
                JSONObject tempObject = newsJSON.getJSONObject(i);

                Resources.news_id[i] = tempObject.getString("id");
                Resources.news_title[i] = tempObject.getString("title");
                Resources.news_descriptionShort[i] = tempObject.getString("description_short");
                Resources.news_descriptionLong[i] = tempObject.getString("description_long");
                Resources.news_date[i] = tempObject.getString("date");
                Resources.news_urgent[i] = tempObject.getString("urgent");
            }
        }catch(JSONException e){
            e.printStackTrace();
        }
        try {
            offersJSON = new JSONArray(Resources.descriptionArray[10]);


        if(offersJSON.length() > 20)
            Resources.offersLength = 20;
        else
            Resources.offersLength = offersJSON.length();

        for(int i = 0; i < Resources.offersLength; i++){
            JSONObject tempObject = offersJSON.getJSONObject(i);

            Resources.offers_id[i] = tempObject.getString("id");
            Resources.offers_offertant[i] = tempObject.getString("Ofertant");
            Resources.offers_description[i] = tempObject.getString("Descriere");
            Resources.offers_contact[i] = tempObject.getString("Contact");
            Resources.offers_date[i] = tempObject.getString("Data");
            Resources.offers_available[i] = tempObject.getString("Valabil");

        } 
        Intent intent = new Intent(FlexFormActivity.this, MainMenu.class);
        startActivity(intent);

        }catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

I’m hoping someone with a bit more experience will be able to explain to me the proper, correct way to go around this crash…

Cheers and thanks to whoever takes the time to answer and help me out…

  • 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-02T02:24:15+00:00Added an answer on June 2, 2026 at 2:24 am

    I would suspect that you are never resetting your descriptionArray_Counter back to 0. So when you execute your task the following line

    Resources.descriptionArray[descriptionArray_Counter] = response;
    

    is probably evaluating to

    Resources.descriptionArray[14] = response;
    

    and your description array is only length 14. You can see in your stack trace that its telling you this exactly.

    • 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
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I am using Paperclip to handle profile photo uploads in my app. They upload
I have some data like this: 1 2 3 4 5 9 2 6
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.