如何在Java中解决“错误:找不到符号”?

时间:2016-04-08 10:25:03

标签: java

public void sort(){

 Node sortedList = null;

   while(sortedList != null){

    Node current = sortedList;
    sortedList = sortedList.next;
    Node x;
    Node previous = null;
    for(x = sortedList; x != null; x = x.next){
        if(current.value < x.value){
                break;
         }
         previous = x;
    }
    if(previous == null){               
          current.next = sortedList;
          sortedList = current;
    }
    else{               
       current.next = previous.next;
       previous.next = current;
    }

  return sortedList;
}}}

这是错误消息:

LinkedList.java:352: error: cannot find symbol
if(current.value < x.value){
           ^
symbol: variable value
location: variable current of type `LinkedList.Node`

1 个答案:

答案 0 :(得分:1)

这是因为方法sort()的返回类型为void,但您尝试从sort()返回值

return sortedList;

查看您的代码,我想您可能希望将其声明为:

public Node sort()

附加说明:您发布的代码段似乎还有其他结束括号}。你可能也需要寻找它。