1

I have the following code:

clientTableList = new Object[DBQueries.getAllClients().size()][3]; [I want to load 3 records for now]
LinkedHashMap<String, LinkedHashMap<String, String>> ClientHashMap = DBQueries.getAllClients();
System.out.println(clientHashMap.keySet());
//Printing all Values
System.out.println(clientHashMap.values());

Results:

[Bob Hope, Elena Hairr, Blossom Kraatz, Loreen Griepentrog]
[{UserID=2345, GivenName=Bob, FamilyName=Hope, DateOfBirth=August 30, 1963, NameSuffix=Sr, NamePrefix=, [email protected], Phone=519- ... 

I need to load a JTable, my next code is:

for (int i = 0; i < clientHashMap.size(); i++) {
 clientTableList[i] = new Object[] {
 clientHashMap.get("GivenName") + " " + clientHashMap.get("FamilyName"),
 clientHashMap.get("LoginEmail") + " ",
 clientHashMap.get("Phone") + " " 
 };

But I'm getting all null for my clientTableList.

I need to load all values into a HashTable then load the HashTable into clientTableList. Right?

Jonny Henly
4,2534 gold badges28 silver badges44 bronze badges
asked Aug 23, 2016 at 20:32
1

2 Answers 2

1

Your clientTableList doesn't have those fields, only its values have them:

int i = 0;
for (Map<String, String> client: clientHashMap.values()) {
 clientTableList[i++] = String.format("%s %s %s %s",
 client.get("GivenName"),
 client.get("FamilyName"),
 client.get("LoginEmail"),
 client.get("Phone"));
};
answered Aug 23, 2016 at 20:40
1
  • Thanks for your reply. Commented Aug 24, 2016 at 14:44
0

Following changes worked:

clientTableList[i++] = new Object[]{ client.get("GivenName") + " " + client.get("FamilyName") , client.get("LoginEmail") + " " , client.get("Phone") + " " };
answered Aug 24, 2016 at 14:42

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.