• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

Can I use array of Beans?

 
Ranch Hand
Posts: 806
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody, I am Chaitanya, I have a link which when clicked requests list of users present. There is a model which selects the list of users with their names.

If it is one single user all his information is retrieved and dumped in to the Bean. Now I am retrieving list of users with their names only. Not the entire details.

I have setter and getter methods in Bean. So if I retrieve 10 user names, then I should have a array of 10 Beans. Can I do like this?

And this Bean consists of 25 setter and getter methods. Here I am using only set user name property. The rest of the setter and getter methods are useless.

Can I go with Beans or simply create an array? If I should go with Beans, then, can I use the previous Bean which consists of 25 setter and getter properties. Or shall I create another Bean which exactly consists the name property?

Thank you all in advance. Have a good day.
 
Marshal
Posts: 67387
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course -- why not? Are you running into any specific difficulty?
 
chaitanya karthikk
Ranch Hand
Posts: 806
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Of course -- why not? Are you running into any specific difficulty?



No Mr. Bear, I don't have any specific difficulty. I just don't know that should I create array of Beans or go for an array. Thats it. Thank you sir.
 
chaitanya karthikk
Ranch Hand
Posts: 806
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mr. Bear, Array of beans is not working, it is reporting a null pointer exception.

Can you please tell me where is the mistake? Thank you in advance.
 
Bear Bibeault
Marshal
Posts: 67387
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to check your basic Java logic.
 
chaitanya karthikk
Ranch Hand
Posts: 806
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:You need to check your basic Java logic.



Everything is fine, it is working with String Array, not with Bean Array. I just replaced the Bean class with String. It worked fine. Coming to Beans it is not working.
 
Ranch Hand
Posts: 754
Eclipse IDE Java
 
chaitanya karthikk
Ranch Hand
Posts: 806
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is giving a null pointer exception Mr. Herbert.
 
Hebert Coelho
Ranch Hand
Posts: 754
Eclipse IDE Java
 
chaitanya karthikk
Ranch Hand
Posts: 806
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hebert Coelho wrote:Wich line?


The error lies in the while loop. I also checked whether there are any records in the faculty table. There are 3 records. So the Bean is initialized to array of size 3.
 
Hebert Coelho
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know this is not the answer you want to hear but, trust me, is the best answer for you...

Bear Bibeault wrote:You need to check your basic Java logic.



When you find it, you won't never fell for it again. [=
 
chaitanya karthikk
Ranch Hand
Posts: 806
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did not understand what you said
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Chaitanya
The way you are creating an array of beans is wrong. Please see this example for a hint.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, the Arrays tutorial.
 
These are the worst of times and these are the best of times. And this is the best tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
    Bookmark Topic Watch Topic
  • New Topic