Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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

3 Answers

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); } – Break Jun 19 '12 at 10:32

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); 
} 
share|improve this answer

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>>>(); ??? :) – Break Jun 20 '12 at 1:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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