This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to access a bean in an arraylist

 
J. Kevin Robbins
Bartender
Pie
Posts: 1607
15
Chrome Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is part of a servlet/JSP app, but I've simplified the problem down to a simple test case and posted it here as a core Java problem.

I have an ArrayList of beans. How do I access the properties of those beans?


The error is "array required, but java.util.List<SimpleBean> found". That's not very helpful. Array required where? I'm reading from an array element. I want the bean and it's properties, not another array.

I know the answer is going to be a forehead-slapper, but I've struggled with this long enough. Can someone please point out the obvious answer for me?

Thanks
 
Billy Nicholson
Greenhorn
Posts: 8
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're accessing an ArrayList as if it were an array.
Try: myList.get(0) to retrieve the bean.
 
J. Kevin Robbins
Bartender
Pie
Posts: 1607
15
Chrome Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doh! Told you it was going to be a forehead-slapper. Both of these work:



Thanks for the help.
 
Billy Nicholson
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No worries!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic