Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

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: 67671
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: 7113
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: 7113
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.
 
The moustache of a titan! The ad of a flea:
The trailboss has a kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic