-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.

3
  • 2
    Doesn't give me any error on my box. Please make sure you're declaring private List<List<List<String>>> 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. Commented Jun 19, 2012 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. Commented Jun 19, 2012 at 10:08
  • Add more code to question. I believe the error is raised on some other line and not what you think. Commented Jun 19, 2012 at 23:09

2 Answers 2

-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.

1
  • i declare: 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).isAllSpecialDays()) { for (int t = 0; t < mListSDayType.size(); t++) { tmp1.add(mListSDayType.get(t).getSpecialDayName()); } } tmp2.add(tmp1); } mListSelectedsSDAY.add(tmp2); } Commented Jun 19, 2012 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

1
  • as you recommended: List mListSelectedsSDAY = new ArrayList<List<List<String>>>(); ??? :) Commented Jun 20, 2012 at 1:36

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.