Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

List<String> returns NULL ?  RSS feed

 
AhFai Chan
Ranch Hand
Posts: 81
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi... again. I was so sure that I got this right, but no

Why isn't my List<String> being populated and why is it returning NULL?

Console output (stubbornly stuck at NULL):
Beer brands: []
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66188
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[] is not null, it's empty. Big difference.
 
Knute Snortum
Sheriff
Posts: 4073
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have two constructors, one with a parameter and one without. Which one are you calling? What does it do?
 
AhFai Chan
Ranch Hand
Posts: 81
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:You have two constructors, one with a parameter and one without. Which one are you calling? What does it do?


I am trying to call the one with the List<String> parameter and I am stumbling over how to insert the parameter in bl.getBrands()

Also, I am working up to a more complex List<String> where printouts would be like "Moose Amber, $2.15" ; "Amber liquid, $1.95" etc
 
Knute Snortum
Sheriff
Posts: 4073
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The way you have it written now, you would either pass in a list

...or you would use the setter.

BTW, why do you have a try/catch block in your setter?
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
AhFai Chan wrote:
Knute Snortum wrote:You have two constructors, one with a parameter and one without. Which one are you calling? What does it do?


I am trying to call the one with the List<String> parameter and I am stumbling over how to insert the parameter in bl.getBrands()

Also, I am working up to a more complex List<String> where printouts would be like "Moose Amber, $2.15" ; "Amber liquid, $1.95" etc


Look like it will be better if you use an Object called Beer instead of a String. The object will then have attributes name and price.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!