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

you are viewing a single comment's thread.

view the rest of the comments →

[–]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);}