-2

I put in system print outs to see where the problem was, and 2 and 7 were the two that kept repeating in the infinite loop. This part of the code is suppose to search a list and find the match that the user puts in, but every time i use the search the GUI freezes or is stuck in an infinite loop. Can anyone help me fix this ?

Here is the code i have:

     if (whichOne.equals("Search"))
    {
        System.out.println("1");
        String[] results = new String [5];
        int count = 1;
        list.moveCursorToRear();
        int last = list.cursor;
        list.resetCursor();
        while(list.hasNext() || list.cursor == last)
        {
            int found = list.search(searchField.getText());
            String result = list.spaces[found].getData();
            System.out.println("2");
            if(current != found)
            {
                list.stepCursorBack();
                System.out.println("3");
                if(list.cursor == list.head)
                {
                    results[count] = result;
                    System.out.println(results[count]);
                    list.spaces[current].setLink(list.spaces[found].getLink());
                    count++;
                    System.out.println("4");
                }
                else
                {
                    results[count] = result;
                    System.out.println(results[count]);
                    list.spaces[current].setLink(list.spaces[list.cursor].getLink());
                    count++;
                    System.out.println("5");
                }
                list.getNext();
                System.out.println("6");
            }
            else
            {
                //break;
                //System.exit(0);
               list.hasNext();
               System.out.println("7");
            }

        }
Oliver Charlesworth
  • 267,707
  • 33
  • 569
  • 680
Joseph Do
  • 23
  • 2
  • 5

1 Answers1

1
    else
    {
        //break;
        //System.exit(0);
       list.hasNext();
       System.out.println("7");
    }

I suspect you wanted list.getNext() here, and not hasNext().

However, without more code - and especially more information about this list, a definite answer might be impossible to be given.

amit
  • 175,853
  • 27
  • 231
  • 333