Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6704181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:15:33+00:00 2026-05-26T07:15:33+00:00

It is a old code and am debugging it. I have a Map (myMap)

  • 0

It is a old code and am debugging it.
I have a Map (myMap) with size 2 (for sure). Keys are null and 1.

SortedSet mySet = new TreeSet();
mySet.addAll(myMap.keySet());
Iterator mySetIterator = mySet.iterator();
while (mySetIterator.hasNext()) {
     Object newObj = mySetIterator.next();
     Object mapObj = myMap.get(newObj);
}

This while loop, iterates for only one time. I am not sure what is wrong here. Is there any problem?

Please help me. Thanks in advance.

Update:

Now I am getting below exception in mySet.addAll(myMap.keySet());

<Oct 18, 2011 12:36:21 PM IST> <Error> <> <BEA-000000> <java.lang.NullPointerException
    at edu.emory.mathcs.backport.java.util.TreeMap.compare(TreeMap.java:934)
    at edu.emory.mathcs.backport.java.util.TreeMap.put(TreeMap.java:97)
    at edu.emory.mathcs.backport.java.util.TreeSet.add(TreeSet.java:149)
    at java.util.AbstractCollection.addAll(AbstractCollection.java:318)
    at edu.emory.mathcs.backport.java.util.TreeSet.addAll(TreeSet.java:165)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T07:15:33+00:00Added an answer on May 26, 2026 at 7:15 am

    Pleas check the compareTo method on the Key Objects.

    If the key object compareTo method indicates that both key objects compare the same then the keyset will have only one value as Set does not allow duplicates. You are using Treeset to store your keys ,so there could be a problem in your compareTo Method.

    Please post the entire code in the context to locate the problem correctly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While refactoring some old code I have stripped out a number of public methods
We have some really old code that calls WebServices using behaviours (webservice.htc), and we
I'm revisiting som old code of mine and have stumbled upon a method for
Found some old code, circa VS 2003. Now I have just VS 2008 (SP1)
I rewrite my old code in new style, like below: #old style open(FD,file); #new
I have some old code written in C for 16-bit using Borland C++ that
In a mixed code project (VB and C#) we were debugging some old Visual
I need debug some old code that uses a Hashtable to store response from
Whilst refactoring some old code I realised that a particular header file was full
Whilst trawling through some old code I came across something similar to the following:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.