method add in ArrayList is not applicable for the arguments (String)

前端 未结 2 1272
眼角桃花
眼角桃花 2021-01-26 06:58

I\'m trying to read a .txt file that contains several lines with the name of a professional carreer in each one of them. I\'ve created a Scanner but whenever I want to add what

相关标签:
2条回答
  • 2021-01-26 07:35

    I guess you are trying to say that the class Claseqla has 2 attributes. If so, then you can create a Claseqla object and set the value of one of the attributes with s.nextline()

    while(s.hasNextLine())
    {
        Claseqla cq = new Claseqla();
        cq.setCareer(s.nextLine());
        clista.add(cq);
    }
    

    This is asumming that you have an attribute named career (String) in your Claseqla class with its respective setter function.

    0 讨论(0)
  • 2021-01-26 07:45

    s.nextLine() returns a String. But your ArrayList has generic type Claseqla. You need to create a Claseqla object using the string you grab from the s.nextLine() call, and then add that object to your ArrayList.

    0 讨论(0)
提交回复
热议问题