• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you. Would I be better doing this in XML rather then using the RandomFile class
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic