type mismatch cannot convert from element type object to string

后端 未结 4 458
日久生厌
日久生厌 2021-01-14 22:15

I keep getting this error when making a search method in my code to search through string. I have gone through alot of examples trying to fix this but I cant find any. Thank

4条回答
  •  不知归路
    2021-01-14 22:30

    You are having exception at this line :

     for (String item : notes)
    

    notes is an ArrayList declared as raw type, although i don't see the declaration i can see this line of initialization:

    notes = new ArrayList();
    

    which sees it's element as of type Object You need to declare notes with ArrayList type such as:

      ArrayList notes = new ArrayList<>();
    

提交回复
热议问题