This question already has an answer here:

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.

share|improve this question

marked as duplicate by Jarrod Roberson java Aug 30 '15 at 21:01

This question was marked as an exact duplicate of an existing question.

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

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.

share|improve this answer
    
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).isAllSpeci‌​alDays()) { 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

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

share|improve this answer
    
as you recommended: List mListSelectedsSDAY = new ArrayList<List<List<String>>>(); ??? :) – Family Jun 20 '12 at 1:36

Not the answer you're looking for? Browse other questions tagged or ask your own question.