GeeCON Prague 2014*
The moose likes Java in General and the fly likes problem with collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "problem with collection" Watch "problem with collection" New topic
Author

problem with collection

Hengki Widjaja
Ranch Hand

Joined: Oct 31, 2011
Posts: 44
I have a class with content like this:


when I use field.get on purchaseCode or purchaseDate, no problem. but when I try to access the purchaseDetail(s), this technique gives me an error. help please? thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

Keeping the error a secret does not help us help you.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Hengki Widjaja
Ranch Hand

Joined: Oct 31, 2011
Posts: 44
Oh, sorry. I forgot
the error message was : cannot convert from object to list.
Harsha Smith
Ranch Hand

Joined: Jul 18, 2011
Posts: 287
TypeCast it to List. Please paste the entire code to help you better
Hengki Widjaja
Ranch Hand

Joined: Oct 31, 2011
Posts: 44






Ah yes, forgot the typecast. it should return 1, 2 and 3. instead, it returned 0,0,3. am I missing something?
Hengki Widjaja
Ranch Hand

Joined: Oct 31, 2011
Posts: 44
ahh, silly mistake. I forgot to change the value from the input file. but I have another question. I had to do this:


to get the value. is there a more generic way, so I don't need to change this for every different type? thanks
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

No, that's the sort of thing you have to do when you use reflection. But why are you using reflection anyway?
Harsha Smith
Ranch Hand

Joined: Jul 18, 2011
Posts: 287
It prints 1,2,3. Please recheck.

Hengki Widjaja
Ranch Hand

Joined: Oct 31, 2011
Posts: 44
@Harsha:
yes, it was some silly mistake. it prints correctly now.

@Paul:
I use reflection to create some sort of simple class parser. So, I got assignment to make a basic ORM project. the class is used to take an object as a parameter and then translate that into a SQL insert string. in order to do this, I need to get the members of the object. now I'm struggling with the cascade insertion (i.e. the member of class that's a collection). any idea? thanks
Hengki Widjaja
Ranch Hand

Joined: Oct 31, 2011
Posts: 44
Thanks for the help, guys. apparently the silly cast is all I need. what a blunder. thanks again. have a nice day!!
As for the cascade, actually it's just a thought. it's not required. so I'll just leave it at that. besides, I don't have any plan of competing with hibernate.
 
GeeCON Prague 2014
 
subject: problem with collection