I have a text file and now am suppose to read the text file and assign it to ArrayList<CourseSection> schedule.
This is what I have so far:
ArrayList<CourseSection> schedule = new ArrayList<CourseSection>(); while(fileReader.hasNextLine()) for (int index = 0; index < schedule.size(); index++) { schedule.add(fileReader.nextLine()) } When I complie I get: cannot find symbol method add(java.util.String)
Jim Yingst
Wanderer
Sheriff
Joined: Jan 30, 2000
Posts: 18670
posted
0
I guess fileReader is a Scanner. The nextLine() method returns a String. Since you've declared your List as an ArrayList<CourseSection>, the add() method expects the argument to be a CourseSection object, not a String. Can you convert the String into a CourseSection object before adding it to the ArrayList? Or, you could use an ArrayList<String> instead.
"I'm not back." - Bill Harding, Twister
Domain
Greenhorn
Joined: Dec 06, 2007
Posts: 4
posted
0
thank you for your post. I will try your suggest. The next problem that I am having is the reader puts everything on one line and the file is a list with ten things.
Domain
Greenhorn
Joined: Dec 06, 2007
Posts: 4
posted
0
what is a CourseSection object? Not sure I understand.
Nicholas Jordan
Ranch Hand
Joined: Sep 17, 2006
Posts: 1282
posted
0
That is a data type that you have written as a Java Object, or it is in the source code of a project that you are working on.
"The differential equations that describe dynamic interactions of power generators are similar to that of the gravitational interplay among celestial bodies, which is chaotic in nature."
Domain
Greenhorn
Joined: Dec 06, 2007
Posts: 4
posted
0
I have had no success in: converting the String into a CourseSection object. Can somebody help?
No one else here knows anything about this "CourseSection" thing. That's something that came from your code. Or code that someone else wrote, but we can't see it. Where did you hear of "CourseSection"? Is it a class that you can look at? Does the class have any constructors, or static methods that return a CourseSection object?