1

I am populating JSON parsed data into Dialog, like this:

String[] colors = new String[] {cArrayList.toString()};
Log.d("colors::-", Arrays.toString(colors));

GETTING

enter image description here

EXPECTED

enter image description here

1
  • String[] colors = new String[]{ cArrayList.size() }; What are you attempting to do here? Create an array of Strings of that size or put the size of that arraylist as the first element in the colors array? Commented Sep 19, 2015 at 5:06

3 Answers 3

2

As per your requirement you can do following if your cArrayList is ArrayList

String[] colors = new String[cArrayList.size()] ;
for(int i=0;i<cArrayList.size();i++)
{
  colors[i]=cArrayList.get(i);
}

Alternatively, you can use the more concise and faster approach:

String[] colors = cArrayList.toArray(new String[cArrayList.size()]);
Sign up to request clarification or add additional context in comments.

4 Comments

getting NPE at this line checkedColors[which] = isChecked; check this: pastebin.com/81PBd4Rd
where you defining checkedColors i dint see initialization of checkedColors
global boolean[] checkedColors = null; @Pavan check this : pastebin.com/81PBd4Rd
0

Like in Core Java you convert int[] to List<Integer> same as the code shows below:

    int[] ints = {100,1000,10000};
    List<Integer> ls = new ArrayList<Integer>();
    for (int index = 0; index < ints.length; index++)
    {
        ls.add(ints[index]);
    }

View reference How to convert int[] into List in Java?

Comments

0

To convert your integer value to a string use:

String.valueOf(insert your integer value here);

1 Comment

It convert your integer value to string

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.