Results 1 to 9 of 9
  1. #1
    Atreides is offline Member
    Join Date
    Jul 2016
    Posts
    8
    Rep Power
    0

    Default Printing malfunctions with nested for loops and HashMap<String,Integer[]>

    Why does this work:
    Java Code:
    for (int i = 0; i < numOfEntries; i++)
    {
        if (tempTableName.equals("items1"))
        {
            dataTable.data.put(DataHandler.ARRAY_STRING_ITEMS[i], intBuffer);
            System.out.print(DataHandler.ARRAY_STRING_ITEMS[i] + "-");
            System.out.print(dataTable.data.get(DataHandler.ARRAY_STRING_ITEMS[i])[0] + "-");
            System.out.print(dataTable.data.get(DataHandler.ARRAY_STRING_ITEMS[i])[1] + "-");
            System.out.print(dataTable.data.get(DataHandler.ARRAY_STRING_ITEMS[i])[2] + "-");
            System.out.print(dataTable.data.get(DataHandler.ARRAY_STRING_ITEMS[i])[3] + "-");
            System.out.print(dataTable.data.get(DataHandler.ARRAY_STRING_ITEMS[i])[4] + "-");
            System.out.print(dataTable.data.get(DataHandler.ARRAY_STRING_ITEMS[i])[5] + "-");
            System.out.print(dataTable.data.get(DataHandler.ARRAY_STRING_ITEMS[i])[6] + "-");
            System.out.print(dataTable.data.get(DataHandler.ARRAY_STRING_ITEMS[i])[7] + "-");
            System.out.print(dataTable.data.get(DataHandler.ARRAY_STRING_ITEMS[i])[8] + "-");
            System.out.print(dataTable.data.get(DataHandler.ARRAY_STRING_ITEMS[i])[9] + "-");
            System.out.print(dataTable.data.get(DataHandler.ARRAY_STRING_ITEMS[i])[10] + "-");
            System.out.print(dataTable.data.get(DataHandler.ARRAY_STRING_ITEMS[i])[11] + "-");
            System.out.print(dataTable.data.get(DataHandler.ARRAY_STRING_ITEMS[i])[12] + "-");
            System.out.print(dataTable.data.get(DataHandler.ARRAY_STRING_ITEMS[i])[13] + "-");
            System.out.print(dataTable.data.get(DataHandler.ARRAY_STRING_ITEMS[i])[14] + "-");
            System.out.print(dataTable.data.get(DataHandler.ARRAY_STRING_ITEMS[i])[15] + "-");
            System.out.print(dataTable.data.get(DataHandler.ARRAY_STRING_ITEMS[i])[16] + "-");
            System.out.print(dataTable.data.get(DataHandler.ARRAY_STRING_ITEMS[i])[17] + "-");
            System.out.print(dataTable.data.get(DataHandler.ARRAY_STRING_ITEMS[i])[18] + "-");
            System.out.print(dataTable.data.get(DataHandler.ARRAY_STRING_ITEMS[i])[19] + "-");
            System.out.print(dataTable.data.get(DataHandler.ARRAY_STRING_ITEMS[i])[20] + "-");
            System.out.print(dataTable.data.get(DataHandler.ARRAY_STRING_ITEMS[i])[21] + "-");
            System.out.print(dataTable.data.get(DataHandler.ARRAY_STRING_ITEMS[i])[22] + "-");
            System.out.print(dataTable.data.get(DataHandler.ARRAY_STRING_ITEMS[i])[23] + "-");
            System.out.print(dataTable.data.get(DataHandler.ARRAY_STRING_ITEMS[i])[24] + "-");
            System.out.print(dataTable.data.get(DataHandler.ARRAY_STRING_ITEMS[i])[25] + "-");
            System.out.print(dataTable.data.get(DataHandler.ARRAY_STRING_ITEMS[i])[26] + "-");
            System.out.print(dataTable.data.get(DataHandler.ARRAY_STRING_ITEMS[i])[27] + "\n");
        }
    }
    Correct output:
    http://pastebin.com/D8dzBspg

    ***

    But this doesn't work?
    Java Code:
    for (int x = 0; x < numOfEntries; x++)
    {
        System.out.print(DataHandler.ARRAY_STRING_ITEMS[x] + "-");
    
        for (int n = 0; n < entrySize; n++)
        {
            System.out.print(dataTable.data.get(DataHandler.ARRAY_STRING_ITEMS[x])[n] + "-");
        }
        System.out.println();
    }
    Incorrect output:
    http://pastebin.com/7fEG2gf0

    ***

    Correct output:
    http://pastebin.com/D8dzBspg

    Incorrect output:
    http://pastebin.com/7fEG2gf0

    If you compare the outputs it looks like the incorrect output is spamming the last entry of the correct output... but the keys fed into the hashmap are themselves correct.

    What is going on here?


    ***


    Relevant file (DataHandler.java, line 77):
    https://bitbucket.org/Atriedes/snake...e-view-default

    Repo:
    https://bitbucket.org/Atriedes/snakeoil/src
    Last edited by Atreides; 08-05-2016 at 01:36 PM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Printing malfunctions with nested for loops and HashMap<String,Integer[]>

    this doesn't work?
    Please explain. Post an example of the output and explain what it wrong with it. Don't post links that many people are not going to follow.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Atreides is offline Member
    Join Date
    Jul 2016
    Posts
    8
    Rep Power
    0

    Default Re: Printing malfunctions with nested for loops and HashMap<String,Integer[]>

    Quote Originally Posted by Norm View Post
    Please explain. Post an example of the output and explain what it wrong with it. Don't post links that many people are not going to follow.
    You mean links you aren't going to follow.

    I posted links to pastebin because the output would take up too much space in my opinion. If you consider pastebin an attack site then, well, there's not much I can do to help you there.

    edit

    Did you miss the part where I explained what was wrong with the output, using the examples I posted to pastebin?

    "If you compare the outputs it looks like the incorrect output is spamming the last entry of the correct output... but the keys fed into the hashmap are themselves correct."
    Last edited by Atreides; 08-05-2016 at 02:15 PM.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Printing malfunctions with nested for loops and HashMap<String,Integer[]>

    You mean links you aren't going to follow.
    Yes, I don't download what an OP needs to post to explain his problem.
    See posts in this thread: http://www.java-forums.org/advanced-...ype-issue.html

    If the real program prints too many lines, reduce them. Either use a smaller input file or change the program or edit the output to only show enough to show the problem.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    Atreides is offline Member
    Join Date
    Jul 2016
    Posts
    8
    Rep Power
    0

    Default Re: Printing malfunctions with nested for loops and HashMap<String,Integer[]>

    Well you asked for it.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Printing malfunctions with nested for loops and HashMap<String,Integer[]>

    the incorrect output is spamming the last entry of the correct output.
    Can you explain what "spamming" means in that context? An example would help.
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    Atreides is offline Member
    Join Date
    Jul 2016
    Posts
    8
    Rep Power
    0

    Default Re: Printing malfunctions with nested for loops and HashMap<String,Integer[]>

    You're not downloading them. Pastebin just holds text.

  8. #8
    Atreides is offline Member
    Join Date
    Jul 2016
    Posts
    8
    Rep Power
    0

    Default Re: Printing malfunctions with nested for loops and HashMap<String,Integer[]>

    Look I'm not going to go through the effort of explaining this if you're too <expletive deleted> lazy to click a link to pastebin or too ignorant to understand that pastebin isn't an attack site.

    You can delete my account, you useless <gesture deleted>.
    Last edited by Tolls; 08-05-2016 at 03:12 PM.

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Printing malfunctions with nested for loops and HashMap<String,Integer[]>

    You can delete my account
    Ok, we can at least ban you if you want. We need a record of your activity and attitude.

    We're all volunteers here. I dont' like having to download several files, correlate them in editor sessions and then try to figure what the problem is. I expect any poster to do most of the work to present his problem in a professional way so that the helpers here can evaluate the code and the problem as shown by the OPs posts.

    Try finding another site if that is too much work for you.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Help with nested for-loops ???
    By Jar in forum New To Java
    Replies: 1
    Last Post: 01-27-2014, 01:17 PM
  2. Replies: 20
    Last Post: 03-22-2011, 04:02 AM
  3. Nested loops
    By Aestuv in forum New To Java
    Replies: 3
    Last Post: 02-10-2011, 11:40 PM
  4. Nested for loops
    By luke in forum New To Java
    Replies: 23
    Last Post: 10-21-2010, 02:49 AM
  5. nested for loops
    By Implode in forum New To Java
    Replies: 4
    Last Post: 09-01-2009, 08:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •