Java - Unable to access a HashMap within a HashMap












-6















I have checked over stack overflow but cannot find a solution to my problem!



I have a class which iterates over chars and turns a data text file into a hashmap, and am having the following problem.



Before I add the HashMap of data-key: value pairs to the HashMap of HashMaps it works fine, and I am able to access this data:



In ConfigHandler.java:



Temporary Map:



Map<String, String> tempHashMap = new HashMap<>();


Code (In a readable format):



this.containers.put(this.currentHashMapKey, tempHashMap);
this.currentHashMapKey = "";
//CHECK KEY, VALUE PAIRS
for(Map.Entry<String, String> entry: tempHashMap.entrySet())
{
String key = entry.getKey();
String value = entry.getValue();

System.out.println(key + ":" + value);
}
tempHashMap.clear()


However once it has been added to the 'Super-HashMap,' though I am able to access the object with its key, the HashMap I get is blank.



(note this also doesn't work when directly within the ConfigHandler class)



In ConfigHandler.java:



public Map<String, Map<String, String>> getContainerList()
{
return this.containers;
}

public Map<String, String> getContainer(String name)
{
return (Map<String, String>)this.containers.get(name);
}


In the static{} method of another class (And In a whole bunch of try/catch):



staticReader.read(readerChars);
oreChanceConfig = new ConfigHandler(readerChars, false);

Map<String, String> chances = oreChanceConfig.getContainer("Chances");

if (oreChanceConfig.getContainerList().containsKey("Chances"))
{
if (chances.containsKey("Saltpeter")) //It should contain this key, but doesn't
{
System.out.println("It actually Works"); //Does not get printed
} else {
System.out.println("Key Value Pairs:"); //this gets printed
//the following loop prints nothing
for (Map.Entry<String, String> entry : chances.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();

System.out.println(key + ":" + value);
}
}
}


HashMap of HashMaps init code:



private Map<String, Map<String, String>> containers = new HashMap<String, Map<String, String>>();









share|improve this question


















  • 4





    Everything would be soooo much easier if, instead of using maps in maps, you defined classes, with names and typed properties and methods. What is clearer? List<User> or Map<String, Map<String, String>>?

    – JB Nizet
    Nov 24 '18 at 23:45








  • 2





    Could your maps be “blank” because you’re executing tempHashMap.clear(); after adding the map to the super map?

    – Bohemian
    Nov 24 '18 at 23:51
















-6















I have checked over stack overflow but cannot find a solution to my problem!



I have a class which iterates over chars and turns a data text file into a hashmap, and am having the following problem.



Before I add the HashMap of data-key: value pairs to the HashMap of HashMaps it works fine, and I am able to access this data:



In ConfigHandler.java:



Temporary Map:



Map<String, String> tempHashMap = new HashMap<>();


Code (In a readable format):



this.containers.put(this.currentHashMapKey, tempHashMap);
this.currentHashMapKey = "";
//CHECK KEY, VALUE PAIRS
for(Map.Entry<String, String> entry: tempHashMap.entrySet())
{
String key = entry.getKey();
String value = entry.getValue();

System.out.println(key + ":" + value);
}
tempHashMap.clear()


However once it has been added to the 'Super-HashMap,' though I am able to access the object with its key, the HashMap I get is blank.



(note this also doesn't work when directly within the ConfigHandler class)



In ConfigHandler.java:



public Map<String, Map<String, String>> getContainerList()
{
return this.containers;
}

public Map<String, String> getContainer(String name)
{
return (Map<String, String>)this.containers.get(name);
}


In the static{} method of another class (And In a whole bunch of try/catch):



staticReader.read(readerChars);
oreChanceConfig = new ConfigHandler(readerChars, false);

Map<String, String> chances = oreChanceConfig.getContainer("Chances");

if (oreChanceConfig.getContainerList().containsKey("Chances"))
{
if (chances.containsKey("Saltpeter")) //It should contain this key, but doesn't
{
System.out.println("It actually Works"); //Does not get printed
} else {
System.out.println("Key Value Pairs:"); //this gets printed
//the following loop prints nothing
for (Map.Entry<String, String> entry : chances.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();

System.out.println(key + ":" + value);
}
}
}


HashMap of HashMaps init code:



private Map<String, Map<String, String>> containers = new HashMap<String, Map<String, String>>();









share|improve this question


















  • 4





    Everything would be soooo much easier if, instead of using maps in maps, you defined classes, with names and typed properties and methods. What is clearer? List<User> or Map<String, Map<String, String>>?

    – JB Nizet
    Nov 24 '18 at 23:45








  • 2





    Could your maps be “blank” because you’re executing tempHashMap.clear(); after adding the map to the super map?

    – Bohemian
    Nov 24 '18 at 23:51














-6












-6








-6








I have checked over stack overflow but cannot find a solution to my problem!



I have a class which iterates over chars and turns a data text file into a hashmap, and am having the following problem.



Before I add the HashMap of data-key: value pairs to the HashMap of HashMaps it works fine, and I am able to access this data:



In ConfigHandler.java:



Temporary Map:



Map<String, String> tempHashMap = new HashMap<>();


Code (In a readable format):



this.containers.put(this.currentHashMapKey, tempHashMap);
this.currentHashMapKey = "";
//CHECK KEY, VALUE PAIRS
for(Map.Entry<String, String> entry: tempHashMap.entrySet())
{
String key = entry.getKey();
String value = entry.getValue();

System.out.println(key + ":" + value);
}
tempHashMap.clear()


However once it has been added to the 'Super-HashMap,' though I am able to access the object with its key, the HashMap I get is blank.



(note this also doesn't work when directly within the ConfigHandler class)



In ConfigHandler.java:



public Map<String, Map<String, String>> getContainerList()
{
return this.containers;
}

public Map<String, String> getContainer(String name)
{
return (Map<String, String>)this.containers.get(name);
}


In the static{} method of another class (And In a whole bunch of try/catch):



staticReader.read(readerChars);
oreChanceConfig = new ConfigHandler(readerChars, false);

Map<String, String> chances = oreChanceConfig.getContainer("Chances");

if (oreChanceConfig.getContainerList().containsKey("Chances"))
{
if (chances.containsKey("Saltpeter")) //It should contain this key, but doesn't
{
System.out.println("It actually Works"); //Does not get printed
} else {
System.out.println("Key Value Pairs:"); //this gets printed
//the following loop prints nothing
for (Map.Entry<String, String> entry : chances.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();

System.out.println(key + ":" + value);
}
}
}


HashMap of HashMaps init code:



private Map<String, Map<String, String>> containers = new HashMap<String, Map<String, String>>();









share|improve this question














I have checked over stack overflow but cannot find a solution to my problem!



I have a class which iterates over chars and turns a data text file into a hashmap, and am having the following problem.



Before I add the HashMap of data-key: value pairs to the HashMap of HashMaps it works fine, and I am able to access this data:



In ConfigHandler.java:



Temporary Map:



Map<String, String> tempHashMap = new HashMap<>();


Code (In a readable format):



this.containers.put(this.currentHashMapKey, tempHashMap);
this.currentHashMapKey = "";
//CHECK KEY, VALUE PAIRS
for(Map.Entry<String, String> entry: tempHashMap.entrySet())
{
String key = entry.getKey();
String value = entry.getValue();

System.out.println(key + ":" + value);
}
tempHashMap.clear()


However once it has been added to the 'Super-HashMap,' though I am able to access the object with its key, the HashMap I get is blank.



(note this also doesn't work when directly within the ConfigHandler class)



In ConfigHandler.java:



public Map<String, Map<String, String>> getContainerList()
{
return this.containers;
}

public Map<String, String> getContainer(String name)
{
return (Map<String, String>)this.containers.get(name);
}


In the static{} method of another class (And In a whole bunch of try/catch):



staticReader.read(readerChars);
oreChanceConfig = new ConfigHandler(readerChars, false);

Map<String, String> chances = oreChanceConfig.getContainer("Chances");

if (oreChanceConfig.getContainerList().containsKey("Chances"))
{
if (chances.containsKey("Saltpeter")) //It should contain this key, but doesn't
{
System.out.println("It actually Works"); //Does not get printed
} else {
System.out.println("Key Value Pairs:"); //this gets printed
//the following loop prints nothing
for (Map.Entry<String, String> entry : chances.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();

System.out.println(key + ":" + value);
}
}
}


HashMap of HashMaps init code:



private Map<String, Map<String, String>> containers = new HashMap<String, Map<String, String>>();






java hashmap nested






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 24 '18 at 23:27









ValoegheseValoeghese

12




12








  • 4





    Everything would be soooo much easier if, instead of using maps in maps, you defined classes, with names and typed properties and methods. What is clearer? List<User> or Map<String, Map<String, String>>?

    – JB Nizet
    Nov 24 '18 at 23:45








  • 2





    Could your maps be “blank” because you’re executing tempHashMap.clear(); after adding the map to the super map?

    – Bohemian
    Nov 24 '18 at 23:51














  • 4





    Everything would be soooo much easier if, instead of using maps in maps, you defined classes, with names and typed properties and methods. What is clearer? List<User> or Map<String, Map<String, String>>?

    – JB Nizet
    Nov 24 '18 at 23:45








  • 2





    Could your maps be “blank” because you’re executing tempHashMap.clear(); after adding the map to the super map?

    – Bohemian
    Nov 24 '18 at 23:51








4




4





Everything would be soooo much easier if, instead of using maps in maps, you defined classes, with names and typed properties and methods. What is clearer? List<User> or Map<String, Map<String, String>>?

– JB Nizet
Nov 24 '18 at 23:45







Everything would be soooo much easier if, instead of using maps in maps, you defined classes, with names and typed properties and methods. What is clearer? List<User> or Map<String, Map<String, String>>?

– JB Nizet
Nov 24 '18 at 23:45






2




2





Could your maps be “blank” because you’re executing tempHashMap.clear(); after adding the map to the super map?

– Bohemian
Nov 24 '18 at 23:51





Could your maps be “blank” because you’re executing tempHashMap.clear(); after adding the map to the super map?

– Bohemian
Nov 24 '18 at 23:51












2 Answers
2






active

oldest

votes


















2














I'm not sure that I really understand your description of what you are doing, but this stands out:



    this.containers.put(this.currentHashMapKey, tempHashMap);
// ...
tempHashMap.clear();


When you call clear(), you remove all entries from tempHashMap. Since this is the map object that you added as a value in the containers map, you are clearing it there as well.



One possible solution is to create a new tempHashMap on every iteration ... and don't call clear() after adding it to containers.





Explanation:




I thought it created a copy of the HashMap when you added it.




You appear to think that



    this.containers.put(this.currentHashMapKey, tempHashMap);


will create a copy of tempHashMap.



This is NOT so.



In fact, what you are doing is storing the reference to your "temporary hash map" as the entry value in the container map. Indeed, if you then reuse the temporary map, you will end up will many references to that one map object in your containers map.



A Map::put(key, value) operation does not copy / clone / whatever the key object or the value object. It just stores the references in the map entry. If you then mutate those objects:




  • mutating the value changes what is visible via the map

  • mutating the key breaks the mapping (!).



Will it not overwrite the previous HashMap whenever I create a new one though?




No it won't. It creates a new one. Consider this:



    Map<String, String> tempHashMap = new HashMap<>();
tempHashMap.put("key", "value");
tempHashMap = new HashMap<>();


The third statement creates a new HashMap object and assigns the reference to the tempHashMap variable. That replaces the original reference value in the variable, but it does not affect the first HashMap object. If you still had a reference to the original object, you could still lookup "key" and get the corresponding "value".



This is basic Java assihnment semantics. Assignment of objects (either by using =, or by passing a parameter) ONLY assigns references. It does NOT overwrite the actual object state.



This is different to C and C++ where assignment of objects (or structs) and assignment of pointers to objects / structs are fundamentally different operations.






share|improve this answer


























  • Will try, Thanks :)

    – Valoeghese
    Nov 24 '18 at 23:55











  • Did you understand why what you are currently doing is wrong?

    – Stephen C
    Nov 25 '18 at 0:00











  • Not Really... I thought it created a copy of the HashMap when you added it. Will it not overwrite the previous HashMap whenever I create a new one though?

    – Valoeghese
    Nov 25 '18 at 0:26













  • HEEEEY It works xD. I initially create the new HashMap<String, String>, then every time I need a new one I just do tempHashMap = new HashMap<String, String>();

    – Valoeghese
    Nov 25 '18 at 0:32





















0














Try replacing this:



Map<String, String> chances = oreChanceConfig.getContainer("Chances");
if (oreChanceConfig.getContainerList().containsKey("Chances")) {
......
}


By this:



Map<String, String> chances = oreChanceConfig.getContainerList().get("Chances");
if (chances != null) {
......
}


Hope this helps!






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53463294%2fjava-unable-to-access-a-hashmap-within-a-hashmap%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    I'm not sure that I really understand your description of what you are doing, but this stands out:



        this.containers.put(this.currentHashMapKey, tempHashMap);
    // ...
    tempHashMap.clear();


    When you call clear(), you remove all entries from tempHashMap. Since this is the map object that you added as a value in the containers map, you are clearing it there as well.



    One possible solution is to create a new tempHashMap on every iteration ... and don't call clear() after adding it to containers.





    Explanation:




    I thought it created a copy of the HashMap when you added it.




    You appear to think that



        this.containers.put(this.currentHashMapKey, tempHashMap);


    will create a copy of tempHashMap.



    This is NOT so.



    In fact, what you are doing is storing the reference to your "temporary hash map" as the entry value in the container map. Indeed, if you then reuse the temporary map, you will end up will many references to that one map object in your containers map.



    A Map::put(key, value) operation does not copy / clone / whatever the key object or the value object. It just stores the references in the map entry. If you then mutate those objects:




    • mutating the value changes what is visible via the map

    • mutating the key breaks the mapping (!).



    Will it not overwrite the previous HashMap whenever I create a new one though?




    No it won't. It creates a new one. Consider this:



        Map<String, String> tempHashMap = new HashMap<>();
    tempHashMap.put("key", "value");
    tempHashMap = new HashMap<>();


    The third statement creates a new HashMap object and assigns the reference to the tempHashMap variable. That replaces the original reference value in the variable, but it does not affect the first HashMap object. If you still had a reference to the original object, you could still lookup "key" and get the corresponding "value".



    This is basic Java assihnment semantics. Assignment of objects (either by using =, or by passing a parameter) ONLY assigns references. It does NOT overwrite the actual object state.



    This is different to C and C++ where assignment of objects (or structs) and assignment of pointers to objects / structs are fundamentally different operations.






    share|improve this answer


























    • Will try, Thanks :)

      – Valoeghese
      Nov 24 '18 at 23:55











    • Did you understand why what you are currently doing is wrong?

      – Stephen C
      Nov 25 '18 at 0:00











    • Not Really... I thought it created a copy of the HashMap when you added it. Will it not overwrite the previous HashMap whenever I create a new one though?

      – Valoeghese
      Nov 25 '18 at 0:26













    • HEEEEY It works xD. I initially create the new HashMap<String, String>, then every time I need a new one I just do tempHashMap = new HashMap<String, String>();

      – Valoeghese
      Nov 25 '18 at 0:32


















    2














    I'm not sure that I really understand your description of what you are doing, but this stands out:



        this.containers.put(this.currentHashMapKey, tempHashMap);
    // ...
    tempHashMap.clear();


    When you call clear(), you remove all entries from tempHashMap. Since this is the map object that you added as a value in the containers map, you are clearing it there as well.



    One possible solution is to create a new tempHashMap on every iteration ... and don't call clear() after adding it to containers.





    Explanation:




    I thought it created a copy of the HashMap when you added it.




    You appear to think that



        this.containers.put(this.currentHashMapKey, tempHashMap);


    will create a copy of tempHashMap.



    This is NOT so.



    In fact, what you are doing is storing the reference to your "temporary hash map" as the entry value in the container map. Indeed, if you then reuse the temporary map, you will end up will many references to that one map object in your containers map.



    A Map::put(key, value) operation does not copy / clone / whatever the key object or the value object. It just stores the references in the map entry. If you then mutate those objects:




    • mutating the value changes what is visible via the map

    • mutating the key breaks the mapping (!).



    Will it not overwrite the previous HashMap whenever I create a new one though?




    No it won't. It creates a new one. Consider this:



        Map<String, String> tempHashMap = new HashMap<>();
    tempHashMap.put("key", "value");
    tempHashMap = new HashMap<>();


    The third statement creates a new HashMap object and assigns the reference to the tempHashMap variable. That replaces the original reference value in the variable, but it does not affect the first HashMap object. If you still had a reference to the original object, you could still lookup "key" and get the corresponding "value".



    This is basic Java assihnment semantics. Assignment of objects (either by using =, or by passing a parameter) ONLY assigns references. It does NOT overwrite the actual object state.



    This is different to C and C++ where assignment of objects (or structs) and assignment of pointers to objects / structs are fundamentally different operations.






    share|improve this answer


























    • Will try, Thanks :)

      – Valoeghese
      Nov 24 '18 at 23:55











    • Did you understand why what you are currently doing is wrong?

      – Stephen C
      Nov 25 '18 at 0:00











    • Not Really... I thought it created a copy of the HashMap when you added it. Will it not overwrite the previous HashMap whenever I create a new one though?

      – Valoeghese
      Nov 25 '18 at 0:26













    • HEEEEY It works xD. I initially create the new HashMap<String, String>, then every time I need a new one I just do tempHashMap = new HashMap<String, String>();

      – Valoeghese
      Nov 25 '18 at 0:32
















    2












    2








    2







    I'm not sure that I really understand your description of what you are doing, but this stands out:



        this.containers.put(this.currentHashMapKey, tempHashMap);
    // ...
    tempHashMap.clear();


    When you call clear(), you remove all entries from tempHashMap. Since this is the map object that you added as a value in the containers map, you are clearing it there as well.



    One possible solution is to create a new tempHashMap on every iteration ... and don't call clear() after adding it to containers.





    Explanation:




    I thought it created a copy of the HashMap when you added it.




    You appear to think that



        this.containers.put(this.currentHashMapKey, tempHashMap);


    will create a copy of tempHashMap.



    This is NOT so.



    In fact, what you are doing is storing the reference to your "temporary hash map" as the entry value in the container map. Indeed, if you then reuse the temporary map, you will end up will many references to that one map object in your containers map.



    A Map::put(key, value) operation does not copy / clone / whatever the key object or the value object. It just stores the references in the map entry. If you then mutate those objects:




    • mutating the value changes what is visible via the map

    • mutating the key breaks the mapping (!).



    Will it not overwrite the previous HashMap whenever I create a new one though?




    No it won't. It creates a new one. Consider this:



        Map<String, String> tempHashMap = new HashMap<>();
    tempHashMap.put("key", "value");
    tempHashMap = new HashMap<>();


    The third statement creates a new HashMap object and assigns the reference to the tempHashMap variable. That replaces the original reference value in the variable, but it does not affect the first HashMap object. If you still had a reference to the original object, you could still lookup "key" and get the corresponding "value".



    This is basic Java assihnment semantics. Assignment of objects (either by using =, or by passing a parameter) ONLY assigns references. It does NOT overwrite the actual object state.



    This is different to C and C++ where assignment of objects (or structs) and assignment of pointers to objects / structs are fundamentally different operations.






    share|improve this answer















    I'm not sure that I really understand your description of what you are doing, but this stands out:



        this.containers.put(this.currentHashMapKey, tempHashMap);
    // ...
    tempHashMap.clear();


    When you call clear(), you remove all entries from tempHashMap. Since this is the map object that you added as a value in the containers map, you are clearing it there as well.



    One possible solution is to create a new tempHashMap on every iteration ... and don't call clear() after adding it to containers.





    Explanation:




    I thought it created a copy of the HashMap when you added it.




    You appear to think that



        this.containers.put(this.currentHashMapKey, tempHashMap);


    will create a copy of tempHashMap.



    This is NOT so.



    In fact, what you are doing is storing the reference to your "temporary hash map" as the entry value in the container map. Indeed, if you then reuse the temporary map, you will end up will many references to that one map object in your containers map.



    A Map::put(key, value) operation does not copy / clone / whatever the key object or the value object. It just stores the references in the map entry. If you then mutate those objects:




    • mutating the value changes what is visible via the map

    • mutating the key breaks the mapping (!).



    Will it not overwrite the previous HashMap whenever I create a new one though?




    No it won't. It creates a new one. Consider this:



        Map<String, String> tempHashMap = new HashMap<>();
    tempHashMap.put("key", "value");
    tempHashMap = new HashMap<>();


    The third statement creates a new HashMap object and assigns the reference to the tempHashMap variable. That replaces the original reference value in the variable, but it does not affect the first HashMap object. If you still had a reference to the original object, you could still lookup "key" and get the corresponding "value".



    This is basic Java assihnment semantics. Assignment of objects (either by using =, or by passing a parameter) ONLY assigns references. It does NOT overwrite the actual object state.



    This is different to C and C++ where assignment of objects (or structs) and assignment of pointers to objects / structs are fundamentally different operations.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 26 '18 at 1:16

























    answered Nov 24 '18 at 23:51









    Stephen CStephen C

    522k70581940




    522k70581940













    • Will try, Thanks :)

      – Valoeghese
      Nov 24 '18 at 23:55











    • Did you understand why what you are currently doing is wrong?

      – Stephen C
      Nov 25 '18 at 0:00











    • Not Really... I thought it created a copy of the HashMap when you added it. Will it not overwrite the previous HashMap whenever I create a new one though?

      – Valoeghese
      Nov 25 '18 at 0:26













    • HEEEEY It works xD. I initially create the new HashMap<String, String>, then every time I need a new one I just do tempHashMap = new HashMap<String, String>();

      – Valoeghese
      Nov 25 '18 at 0:32





















    • Will try, Thanks :)

      – Valoeghese
      Nov 24 '18 at 23:55











    • Did you understand why what you are currently doing is wrong?

      – Stephen C
      Nov 25 '18 at 0:00











    • Not Really... I thought it created a copy of the HashMap when you added it. Will it not overwrite the previous HashMap whenever I create a new one though?

      – Valoeghese
      Nov 25 '18 at 0:26













    • HEEEEY It works xD. I initially create the new HashMap<String, String>, then every time I need a new one I just do tempHashMap = new HashMap<String, String>();

      – Valoeghese
      Nov 25 '18 at 0:32



















    Will try, Thanks :)

    – Valoeghese
    Nov 24 '18 at 23:55





    Will try, Thanks :)

    – Valoeghese
    Nov 24 '18 at 23:55













    Did you understand why what you are currently doing is wrong?

    – Stephen C
    Nov 25 '18 at 0:00





    Did you understand why what you are currently doing is wrong?

    – Stephen C
    Nov 25 '18 at 0:00













    Not Really... I thought it created a copy of the HashMap when you added it. Will it not overwrite the previous HashMap whenever I create a new one though?

    – Valoeghese
    Nov 25 '18 at 0:26







    Not Really... I thought it created a copy of the HashMap when you added it. Will it not overwrite the previous HashMap whenever I create a new one though?

    – Valoeghese
    Nov 25 '18 at 0:26















    HEEEEY It works xD. I initially create the new HashMap<String, String>, then every time I need a new one I just do tempHashMap = new HashMap<String, String>();

    – Valoeghese
    Nov 25 '18 at 0:32







    HEEEEY It works xD. I initially create the new HashMap<String, String>, then every time I need a new one I just do tempHashMap = new HashMap<String, String>();

    – Valoeghese
    Nov 25 '18 at 0:32















    0














    Try replacing this:



    Map<String, String> chances = oreChanceConfig.getContainer("Chances");
    if (oreChanceConfig.getContainerList().containsKey("Chances")) {
    ......
    }


    By this:



    Map<String, String> chances = oreChanceConfig.getContainerList().get("Chances");
    if (chances != null) {
    ......
    }


    Hope this helps!






    share|improve this answer




























      0














      Try replacing this:



      Map<String, String> chances = oreChanceConfig.getContainer("Chances");
      if (oreChanceConfig.getContainerList().containsKey("Chances")) {
      ......
      }


      By this:



      Map<String, String> chances = oreChanceConfig.getContainerList().get("Chances");
      if (chances != null) {
      ......
      }


      Hope this helps!






      share|improve this answer


























        0












        0








        0







        Try replacing this:



        Map<String, String> chances = oreChanceConfig.getContainer("Chances");
        if (oreChanceConfig.getContainerList().containsKey("Chances")) {
        ......
        }


        By this:



        Map<String, String> chances = oreChanceConfig.getContainerList().get("Chances");
        if (chances != null) {
        ......
        }


        Hope this helps!






        share|improve this answer













        Try replacing this:



        Map<String, String> chances = oreChanceConfig.getContainer("Chances");
        if (oreChanceConfig.getContainerList().containsKey("Chances")) {
        ......
        }


        By this:



        Map<String, String> chances = oreChanceConfig.getContainerList().get("Chances");
        if (chances != null) {
        ......
        }


        Hope this helps!







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 25 '18 at 0:02









        Claudivan MoreiraClaudivan Moreira

        563




        563






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53463294%2fjava-unable-to-access-a-hashmap-within-a-hashmap%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Tonle Sap (See)

            I get strange results when I access the Sqlitedatabase with Unity C# via XAMPP

            Guatemaltekische Davis-Cup-Mannschaft