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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:28:54+00:00 2026-06-08T12:28:54+00:00

I have an activity which has the following variable static CharSequence[] categories; I’m receiving

  • 0

I have an activity which has the following variable

static CharSequence[] categories;

I’m receiving data using JSON

try
{
    Thread cThread = new Thread(new getStringContent("http://192.168.0.101/curltest/getcategories.php"));
    cThread.start();            
}
catch(Exception ex)
{
    Log.i("YGo", ex.toString());
}

public class getStringContent implements Runnable {
        String suri;
        public getStringContent(String uri)
        {
            suri = uri; 
        }
        @Override
        public void run() {         
            try {
                JSONArray jsonArray = new JSONArray(getPageContent(suri));
                for (int i = 0; i < jsonArray.length(); i++) {
                    JSONArray jsonSArray = jsonArray.getJSONArray(i);
                    categories = new CharSequence[jsonArray.length()];
                    categories[i] = jsonSArray.getString(0);
                    Log.i("YGo", categories[i].toString());
                }               
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                Log.e("YGo", e.toString());
            }
            dialog.dismiss();
        }       
    }

In the GUI thread if I click on the button, I would like to display the received data:

for(int i=0; i<categories.length; i++)
{
   Log.i("Ygo", String.valueOf(categories[i]));
   Log.i("Ygo", String.valueOf(selectedData[i]));
}
AlertDialog.Builder builder = new AlertDialog.Builder(PreferencesClass.this);
            builder.setTitle("Pick categories");

            builder.setMultiChoiceItems(categories, selectedData, onClickCatChooser);           
            builder.setPositiveButton("Ok", clickedOnClickCatOk);

            AlertDialog alert = builder.create();
            alert.show();

but in the categories variable I have null,null,Data3, instead of Data1 and Data2 I have only null. Why?

  • 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-08T12:28:55+00:00Added an answer on June 8, 2026 at 12:28 pm

    The line

    categories = new CharSequence[jsonArray.length()];
    

    should be outside the for loop. You reset the data with each iteration in the loop, so in the end you only have data left from the last operation.

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

Sidebar

Related Questions

In my application i have an activity which has the following layout <?xml version=1.0
I have a activity which has a button and 2 autocomplete widget. for the
Guys I have an activity which has a home button, when the button is
I have an Activity class which has an attribute that references an AsyncTask instance
So I have an Activity which has a FragmentPagerAdapter and inside each fragment I
I have the following scenario (note that activity A has launchMode=singleTop ): Activity A
I have a launching Activity A1 which has a start button which starts a
I am new to NDK. I have a cpp file which has the following
I have a application developed in ActionScript 2 which has dragging/dropping activity. which works
In my Android application, I have a fragment activity which it has a progressbar.

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.