aspose file tools*
The moose likes Beginning Java and the fly likes Arraylist Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Arraylist" Watch "Arraylist" New topic
Author

Arraylist

Lari Hopkins
Ranch Hand

Joined: Nov 23, 2006
Posts: 37
Absolute beginner here. I have an araylist to construct and a txt file to be read into it, any tips on how to do this will be gratefully received.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Show us what you have so far, and tell us where you're stuck.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14269
    
  21

The following tutorials might contain useful information:

Collections (about how to use collection classes like ArrayList)
Basic I/O


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Lari Hopkins
Ranch Hand

Joined: Nov 23, 2006
Posts: 37
Here is my filereader so far, I have got a readout from the txt file, but am having problems adding them to arrayLists. I have added the following but then taken it out as it doesn't seem to work, which I think is a problem with my constructor in Car.java. Any tips on setting up the constructor?



EDIT by mw: Added Code Tags.
[ January 19, 2007: Message edited by: marc weber ]
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3672
    
  15
Try using code tags when posting code in future - it makes it easier to read.
Having said that I can see a couple of problems.

You declare carlist as an ArrayList that contains Strings, but you are adding Car objects to it. Change the declaration to


Later on in your code you try to assign a Car object to carlist

Get rid of the middle line, not only is it wrong, you don't need actually need it as you have already created your ArrayList.

Make those changes and if it still doesn't work, tell us what the problem is - if it doesn't compile tell us what the error messages are - if it doesn't do what you want, tell us what it is doing and what you expected it to do.


Joanne
Lari Hopkins
Ranch Hand

Joined: Nov 23, 2006
Posts: 37
Thanks, I have made those changes, however I still have a Car class with no constructor as I'm not sure what to write. Also the following compilor errors have come up:

3 errors found:
File: C:\Documents and Settings\Lari\My Documents\Huddersfield\Programming\Coursework2\DemoFileReader.java [line: 61]
Error: cannot find symbol
symbol : constructor Car(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String)
location: class Car
File: C:\Documents and Settings\Lari\My Documents\Huddersfield\Programming\Coursework2\DemoFileReader.java [line: 61]
Error: internal error; cannot instantiate Car.<init> at Car to ()
File: C:\Documents and Settings\Lari\My Documents\Huddersfield\Programming\Coursework2\DemoFileReader.java [line: 62]
Error: non-static variable carList cannot be referenced from a static context


Lines 61/2 =
Car car = new Car(reg, make, model, colour, passenger_no);
carList.add(car);
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Arraylist