aspose file tools*
The moose likes Beginning Java and the fly likes How do I  declare an arrayList and initilise it in  a constructor Method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How do I  declare an arrayList and initilise it in  a constructor Method" Watch "How do I  declare an arrayList and initilise it in  a constructor Method" New topic
Author

How do I declare an arrayList and initilise it in a constructor Method

lupercal hill
Greenhorn

Joined: Sep 28, 2005
Posts: 9
I am trying to extend wordRecord class by Record, record will be used to write randomly to disk.

I am having problems with using arrayLists. Can you please tell me what Im doing wrong. How do I declare an arrayList and initilise it in a constructor Method.

My code is below

Record class




wordRecord class

Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


How do I declare an arrayList and initilise it in a constructor Method



There you go.

I am presuming you have not tried to compile your code yet? It doesn't look like it will compile - I don't see a wordRecord constructor which takes any parameters.
[ October 04, 2005: Message edited by: Paul Sturrock ]

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Seb Mathe
Ranch Hand

Joined: Sep 28, 2005
Posts: 225
It does'nt work because your wordRecord class does'nt have a constructor that match :
wordRecord(int correctAttempts, int incorrectAttempts, int location, String englishWord, String foreignWord, ArrayList categories)

Add this constructor to your wordRecord class, do variables affectations here and it will work fine...

Tips :
- rename wordRecord to WordRecord
- no-arg constructor wordRecord() will just have do call this(0,0,..., ) just like you do in Record


Regards,<br />Seb<br /> <br />SCJP 1.4
lupercal hill
Greenhorn

Joined: Sep 28, 2005
Posts: 9
Is this more correct. Thanks for you help. Im leaving out the arraylists as I dont know how difficult they will be to save to disk. They are non fixed size but the records must be a fixed size. I dont know the work around yet.

Could you please look at this code and suggest what else i need to change. The final class Create RandomFile wont compile.

Record Class




WordRecord Class






Create RandomFile class


Seb Mathe
Ranch Hand

Joined: Sep 28, 2005
Posts: 225
It seems to be ok...

But look at your WordRecord constructors... You're doing the same things. You can simplify the no-arg constructor.
lupercal hill
Greenhorn

Joined: Sep 28, 2005
Posts: 9
Thank you. Would I be better doing this in XML rather then using the RandomFile class
 
jQuery in Action, 2nd edition
 
subject: How do I declare an arrayList and initilise it in a constructor Method