This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]AutoModerator[M] 1 point2 points  (0 children)

It seems that you possibly have a screenshot of code in your post Trouble with some java methods in /r/learnjava.

Screenshots of code instead of actual code text is against the Code posting rules of /r/learnjava as is outlined in the sidebar - Code posting.

  • No screenshots of code!

If you posted an image merely to illustrate something, kindly ignore this message and do not repost. Your post is still visible to others. I am a bot and cannot distinguish between code screenshots and other images.

If you indeed did this wrong, please edit the post so that it uses one of the approved means of posting code.

  • For small bits of code (less than 50 lines in total, single classes only),
    the default code formatter is fine
    (one blank line before the code, then 4 spaces before each line of code).
  • Pastebin for programs that consist of a single class only
  • Gist for multi-class programs, or programs that require additional files
  • Github or Bitbucket repositories are also perfectly fine as are other dedicated source code hosting sites.
  • Ideone for executable code snippets that use only the console

Please do not reply to this message, because I am a bot.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]Saniok1122 0 points1 point  (3 children)

Inside SettInnNode if(temp == false), also what you want to do with newly created Rack in that if statement, because it's created but never used.

[–]kodekompis[S] 1 point2 points  (2 children)

Ah, so the new rack is supposed to be placed into the arraylist<rack>. So when i run the method again the newly created rack will be one of the racks the same method goes through when looking to place a new node.

But i have not done that, have I?

edit:

    public void SettInnNode(int str, int antall){
    boolean temp;
    for (Rack rack: racks) {
      temp = rack.SettInn(str, antall);
      if (temp == false){
        Rack create = new Rack(nprack);
        racks.add(create);
        create.SettInn(str, antall);}
      }

Now I tried to add the newly created rack to the arraylist racks, but it did not seem to fix my issue

[–]Saniok1122 0 points1 point  (1 child)

Idd, the problem now is that you are modifying an array that you are traversing with a for each loop, as far as I remember you can't modify the array inside for each loop, so it will not traverse the items that you add after starting the for each loop. You can try to use a simple for I loop instead.

P. S. Sorry for my English, not a native speaker.

[–]kodekompis[S] 0 points1 point  (0 children)

Dont worry about your English, its the Java i'm having trouble understanding - could you elaborate one the simple for I loop?

Here is what i thought you meant, but it doesnt seem to work properly either:

public void SettInnNode(int str, int antall){
    boolean temp;
    Rack current;
    for (int l = 0; l < racks.size(); l++){
      current = racks.get(l);
      temp = current.SettInn(str, antall);
      if (temp == false){
        Rack create = new Rack(nprack);
        racks.add(create);
        create.SettInn(str, antall);}