required java.util.ArrayList,found java.lang.Object : I do not understand the reason for this error

前端 未结 7 1283
逝去的感伤
逝去的感伤 2021-01-28 09:30

Following are some snippets from a jsp page:

<%! ArrayList songList = new ArrayList(); %>

    <%
        songList = StoreSongLink.linkLis         


        
7条回答
  •  一向
    一向 (楼主)
    2021-01-28 10:08

    While you assign songList a new ArrayList, you're defining the songList as an arrayList (which is arrayList). That would make it okay to iterate over songList as Objects. But you're actually iterating over songList as ArrayList.

    So in short, you need to switch songList to be decared to ArrayList and you need to iterate over songList with Strings, not ArrayList.

提交回复
热议问题