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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:18:47+00:00 2026-06-12T19:18:47+00:00

Here is my AsyncTask. Getting exception in the AsyncTask.. private class GetCategories extends AsyncTask<String,

  • 0

Here is my AsyncTask. Getting exception in the AsyncTask..

private class GetCategories extends AsyncTask<String, Void, String[]> {
    String temp[] = new String[] {};
    protected String[] doInBackground(String... urls) {
        JSONParser jParser = new JSONParser();
        JSONArray category_details;
        try {
            URL url = new URL(urls[0]);
            JSONObject json = jParser.getJSONFromUrl(url.toString());
            category_details = json.getJSONArray("cat");
            for (int i = 0; i < category_details.length(); i++) {
                JSONObject obj = category_details.getJSONObject(i);
                temp[i] = obj.getString("catName");
            }
            return temp;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }

    }

    @Override
    protected void onPostExecute(String[] temp) {

    }

}

I am excuting the task and fetching the value like this.

  try {
        String[] test = new GetCategories().execute(categories_url).get();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ExecutionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

But I am getting error like this. I am getting exception inside the doInBackground method.

10-11 15:26:47.207: W/System.err(5158): java.lang.ArrayIndexOutOfBoundsException: length=0; index=0
10-11 15:26:47.207: W/System.err(5158):     at com.example.fragments.CatFragment$GetCategories.doInBackground(CategoriesFragment.java:207)
10-11 15:26:47.207: W/System.err(5158):     at com.example.fragments.CatFragment$GetCategories.doInBackground(CategoriesFragment.java:1)
10-11 15:26:47.207: W/System.err(5158):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
10-11 15:26:47.207: W/System.err(5158):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
10-11 15:26:47.207: W/System.err(5158):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
10-11 15:26:47.207: W/System.err(5158):     at  android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
10-11 15:26:47.207: W/System.err(5158):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
10-11 15:26:47.207: W/System.err(5158):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
10-11 15:26:47.207: W/System.err(5158):     at java.lang.Thread.run(Thread.java:856)

The line 207 goes to the catch block. Can anyone point out what I am doing wrongly here?

  • 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-12T19:18:49+00:00Added an answer on June 12, 2026 at 7:18 pm

    i think, this exception caused by incorrect string array declaration
    you can use this this tutorial
    1) Declaring a Java String array with an initial size
    If you know up front how large your array needs to be, you can (a) declare a String array and (b) give it an initial size like this:

    public class JavaStringArrayTests
    {
      private String[] toppings = new String[20];
      // more to the class here ...
    }
    

    In this example, we declare a String array named toppings, and then give it an initial size of 20 elements.

    Later on, in a Java method in your class, you can populate the elements in the String array like this:

    void populateStringArray()
    {
      toppings[0] = "Cheese";
      toppings[1] = "Pepperoni";
      toppings[2] = "Black Olives";
      // ...
    }
    

    source: http://alvinalexander.com/java/java-string-array-reference-java-5-for-loop-syntax

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

Sidebar

Related Questions

private class ExecuteLocations extends AsyncTask<String, Void, Void>{ private final ProgressDialog dialog = new ProgressDialog(ListProfiles.this);
Update based on @Tom solution: SongsManager.java public class SongsManager extends AsyncTask<Void, Void, ArrayList<HashMap<String, String>>>
private class DownloadLargeFileTask extends AsyncTask<Void, Void, Void> { private final ProgressDialog dialog; public DownloadLargeFileTask(ProgressDialog
Here is my AsyncTask. Getting JSONException inside the doInbackground method. try { Log.v(thisurl, url);
I have created a new class called Get_WebPage1 and init I have extends that
I keep getting a CalledFromWrongThreadException even if i throw it into AsyncTask's DoInBackground method!
i have written the code like below public class SplashScreen extends BaseActivity{ public void
Here is where i am getting a error at.. in the doInBackground in my
Getting this error: java.lang.RuntimeException: An error occured while executing doInBackground() at android.os.AsyncTask$3.done(AsyncTask.java:200) at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
Why am i getting this null pointer exception. Here is my code I am

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.