File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Text file to ArrayList Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Text file to ArrayList" Watch "Text file to ArrayList" New topic
Author

Text file to ArrayList

Domain
Greenhorn

Joined: Dec 06, 2007
Posts: 4
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
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
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
what is a CourseSection object? Not sure I understand.
Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
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
I have had no success in: converting the String into a CourseSection object. Can somebody help?
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18670
"Domain", please check your private messages. Thanks.

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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Text file to ArrayList
 
Similar Threads
help on jsp and xml
Submit button-simple question
need help on jsp and xml
Swing components not updating with current values
Retrieve objects from ArrayList