Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
lupercal hill
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 ]
 
Seb Mathe
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
lupercal hill
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. Would I be better doing this in XML rather then using the RandomFile class
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic