-1

I have a List, which I am trying to use in 2 different ways...

private List<List<List<String>>> mListSelectedsWeekDAY;

// technique 1
for(int t = 0; t < mListSelectedsWeekDAY.get(0).get(0).size();t++){
    ...
}

// technique 2
List<String> tmpList = mListSelectedsWeekDAY.get(0).get(0);

And my list is populated like this...

mListSelectedsSDAY = new ArrayList<List<List<String>>>(); 
for (int i = 0; i < mListTimeBand.size(); i++) { 
    List<List<String>> tmp2 = new ArrayList<List<String>>(); 
    for (int j = 0; j < mListTimeBand.get(i).getTimeBandDefList().getTimeBandDefini().size(); j++) { 
        List<String> tmp1 = new ArrayList<String>(); 
        if (mListTimeBand.get(i).getTimeBandDefList().getTimeBandDefini().get(j).isAllSpeci‌​alDays()) { 
            for (int t = 0; t < mListSDayType.size(); t++) { 
                tmp1.add(mListSDayType.get(t).getSpecialDayName()); 
            } 
        }
        tmp2.add(tmp1); 
    }

    mListSelectedsSDAY.add(tmp2); 
}

However my code it always giving the following error...

java.lang.ClassCastException: [Ljava.lang.String; cannot be cast to java.util.List

Could someone please help me understand why this is happening.

wattostudios
  • 8,666
  • 13
  • 43
  • 57
Family
  • 41
  • 1
  • 2
  • 10
  • 2
    Doesn't give me any error on my box. Please make sure you're declaring `private List>> mListSelectedsWeekDAY;` the correct way. Can you please show more of your code, specially on how you populate `mListSelectedsWeekDAY`? Also as Thilo says, compiler should shout at you. – m0skit0 Jun 19 '12 at 10:08
  • 5
    You got a `String[]` in there. Against the type annotation. How did you put that in the list? There should be a compiler warning somewhere. – Thilo Jun 19 '12 at 10:08
  • Add more code to question. I believe the error is raised on some other line and not what you think. – Ankit Jun 19 '12 at 23:09

2 Answers2

-1

One possible situation may be is that, in your series of Get methods(), you are moving ahead to get Strings and assigning it to List variables.

Ahmad
  • 2,110
  • 5
  • 26
  • 36
  • i declare: mListSelectedsSDAY = new ArrayList>>(); for (int i = 0; i < mListTimeBand.size(); i++) { List> tmp2 = new ArrayList>(); for (int j = 0; j < mListTimeBand.get(i).getTimeBandDefList().getTimeBandDefini().size(); j++) { List tmp1 = new ArrayList(); if (mListTimeBand.get(i).getTimeBandDefList().getTimeBandDefini().get(j).isAllSpecialDays()) { for (int t = 0; t < mListSDayType.size(); t++) { tmp1.add(mListSDayType.get(t).getSpecialDayName()); } } tmp2.add(tmp1); } mListSelectedsSDAY.add(tmp2); } – Family Jun 19 '12 at 10:32
-1

You actually have a List<List<String>>, not a List<List<List<String>>>.

You must be using a raw List type somewhere for this to happen

Trying
  • 14,004
  • 9
  • 70
  • 110
Bohemian
  • 412,405
  • 93
  • 575
  • 722