type mismatch cannot convert from element type object to string

*爱你&永不变心* 提交于 2019-12-01 10:38:05

Add notes as a global variable to your class

public class Notebook{
ArrayList<String> notes = null;

....
}

In the constructor, do:

public Notebook()
{
    notes = new ArrayList<String>();
}

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<String> type such as:

  ArrayList<String> notes = new ArrayList<>();

try this: notes = new ArrayList<String>();

You don't declare the notes variable

public class Notebook{
  private ArrayList<String> notes;
...
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!