• 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

List<String> returns NULL ?

 
Ranch Hand
Posts: 271
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: []
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[] is not null, it's empty. Big difference.
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 271
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic