[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Error message when display values in HashMap

Posted on 2004-10-29
3
Medium Priority
?
409 Views
Last Modified: 2011-09-20
How do I display the values in HashMap in JSP page? I use the following code, I can get HashMap and display the value in it, but I got error messages. Please help

LabelSession label = null;      
 HashMap labelHash= null;
try{                                            
   int id = 1002478;
   Context context = UtilHelper.getInitialContext();
   Object object =context.lookup("ejb/com/sbc/nd/ejb/traffic_report/LabelSessionHome");
   LabelSessionHome home = (LabelSessionHome)PortableRemoteObject.narrow(object, LabelSessionHome.class);
  label = home.create();                                        
  labelHash = label.getLabel(id);                                      
  System.out.println("labelHash::"+labelHash);
                                                             
  Set keySet = labelHash.keySet();
  System.out.println("keySet :"+keySet );
  Iterator conItor = labelHash.values().iterator();
  System.out.println("conItor :"+conItor );
  Iterator keyItor = keySet.iterator();
  System.out.println("keyItor :"+keyItor );
  while( keyItor.hasNext()){
                                    String content = (String)conItor.next();                            
                                     System.out.println("content: "+content);
                            %>      
                              <option ><%=content %></option>
                            <%   }
                               }catch (Exception exception){
                                 out.println("Exception occured ... " + exception.getMessage());
                                 exception.printStackTrace();
                               }
                             %>                                    
                           </select>      

[10/28/04 19:32:37:325 PDT] 2a6e10cf SystemErr     R java.util.NoSuchElementException
[10/28/04 19:32:37:325 PDT] 2a6e10cf SystemErr     R at java.util.HashMap$HashIterator.nextEntry(HashMap.java(Compiled Code))
[10/28/04 19:32:37:325 PDT] 2a6e10cf SystemErr     R at java.util.HashMap$ValueIterator.next(HashMap.java(Compiled Code))
                 
0
Comment
Question by:jen2483
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 13

Expert Comment

by:petmagdy
ID: 12446997
not like this

 while( keyItor.hasNext()){
                                    String key= (String)keyItor.next();          
                                    String content = labelHash.get(key);
                                     System.out.println("content: "+content);
                            %>    
                              <option ><%=content %></option>
                            <%   }
                               }catch (Exception exception){
                                 out.println("Exception occured ... " + exception.getMessage());
                                 exception.printStackTrace();
                               }
                             %>        
0
 
LVL 13

Expert Comment

by:petmagdy
ID: 12447018
>>not like this

sorry i mean like this

....
0
 
LVL 3

Accepted Solution

by:
Gunt earned 1000 total points
ID: 12449596
If you need to get both key and value during the iteration, the best method is to iterate the entrySet:

for (Iterator iter = map.entrySet().iterator(); iter.hasNext() ; ) {
  Map.Entry entry = (Map.Entry) iter.next();
  System.out.println("Key is: " + entry.getKey());
  System.out.println("Value is: " + entry.getValue());
}
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

WooCommerce is becoming the most powerful e-commerce plugin for Wordpress. And why not. The platform comprises of numerous core plugins that may come in handy, powerful options to make your website development task much easier.
What monsters are hiding in your child's room? In this article I will share with you a tech horror story that could happen to anyone, along with some tips on how you can prevent it from happening to you.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question