Debugging help with hashmap - Java Android

Does that code actually compile and run for you, as there seems to be an error. I think some of your problem stems from this block of code;

Set<Integer> selectedSet = new HashSet<>();     
for (Integer keys : twistedThinking) {          // This line should not compile
    if (twistedThinking != null) {              
        selectedSet.add(keys);
    }     
}

I'm assuming that you want the for loop to go through every key in the set. However as "twistedThinking" is of the type HashMap and not some itterable object of keys, you can't do that explicitly. If you just want to go through each of the keys in the HashMap then you need to get the key set;

for (Integer key : twistedThinking.keySet())

This will then loop through every key included in the twistedThinking HashMap. It is also worth mentioning that the if statement is redundant, because if twistedThinking was null then the loop would have already failed. So that if statement can be removed.

As for the exact error you are getting, I'm unsure. When I run the snippet of code you have given me, it just selects all the keys every time (once I fixed the error mentioned above). You mention user selection, however none of this is shown in the code you provided, and you don't seem to use any variables which have been set by the user.

Could you provide some more detail on what it is you are building? I get the feeling you may be way overcomplicating a simple problem.

/r/learnprogramming Thread