• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can I use array of Beans?

 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65519
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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
Java MySQL Database Spring
  • 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
Java MySQL Database Spring
  • 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
Author and ninkuma
Marshal
Posts: 65519
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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
Java MySQL Database Spring
  • 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.
 
Hebert Coelho
Ranch Hand
Posts: 754
Eclipse IDE Java
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • 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
Java MySQL Database Spring
  • 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
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did not understand what you said
 
Nilesh Miskin
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.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, the Arrays tutorial.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!