Question: Please help me understand, the below code is showing Type mismatch: "cannot convert from element type Object to List" in the for statement. I know I'm missing something silly. Please help.

```
public void setMapPriceValue(SolrItemVO solrItemVO, ArrayList proce1) throws SolrDAOException
{
    List xcatentAttrList = (List<Xcatentattr>) proce1.get(0);

    solrItemVO.setMapPrice(-1); // setting default value

    for(List  xcatentattr : xcatentAttrList){

        if(xcatentattr.get(0) == 33)

                solrItemVO.setMapPrice(xcatentattr.get(1));

                solrItemVO.setMapPriceVal(xcatentattr.get(2));

        }

}

```

Answer: 
If you are going to type things try and keep them typed

```
List<Xcatentattr> xcatentAttrList = (List<Xcatentattr>) proce1.get(0);

solrItemVO.setMapPrice(-1); // setting default value

for(Xcatentattr  xcatentattr : xcatentAttrList){

    if(xcatentattr.get(0) == 33)

            solrItemVO.setMapPrice(xcatentattr.get(1));

            solrItemVO.setMapPriceVal(xcatentattr.get(2));

    }
}

```

then the answer might be clearer ;)

The for loop is of type Xatentattr. You are looping through the list of that type.

Take a look at this [link](https://blogs.oracle.com/CoreJavaTechTips/entry/using_enhanced_for_loops_with) for more info on for-each loops
There are two issues here.

* First, if you declare `List xcatentAttrList` without using generics, Java can only know that your list contains `Object`s. So your `for` loop would have to iterate through a list of `Object`s.
* Second, the cast `(List<Xcatentattr>)proce1` implies the list contains `Xcatentattr` elements, and yet you are iterating through `List` objects.

So provided you had declared the `List` using generics (and therefore saying you are working with a list of `Xcatentattr` elements), the loop `for` would be:

```
 for (Xcatentattr xcatentattr : xcatentAttrList) {
     . . .
 }

```