在类之间找不到符号

时间:2015-11-17 05:54:41

标签: java class nodes

我正在创建一个程序来创建一个霍夫曼树。当我到达第31行(node [i] = setFreq(freq);)时,我的编译器返回错误“找不到符号”,符号为“方法setFreq(int)”,位置为“class Huffman”。据我所知,node [i]正在以NodeType正确初始化,但不会回到上面提到的那一行。下面是我的代码部分应该是所有必要的(如果不是,请道歉)。输入表将是字母频率的后续行,即: A-3 B-32 C-23 等等 感谢您提前提供任何帮助。

import java.io.*;
import java.util.*;
public class Huffman{
    final static int MAXBITS = 138;
    final static int MAXSYMBS = 138;
    final static int MAXNODES = 255;

    public static void Huffman(){
       CodeType cd = new CodeType();
       CodeType code[] = new CodeType[MAXSYMBS];
       NodeType node[] = new NodeType[MAXNODES];
       int i, k, p, o, q, root, freq;
       DynamicList rootNodes = new DynamicList();
       char symb;
       char alph[] = new char[MAXSYMBS];

       for (i=0; i<MAXSYMBS; i++){
           alph[i] = ' ';
       }

       try (BufferedReader br = new BufferedReader(new FileReader("HuffmanTable.txt"))){
          String line;
          i=0;
          while ((line = br.readLine()) != null){
              String[] parts = line.split("-");
              node[i] = new NodeType();
              String trick = parts[0];
              symb = trick.charAt(0);
              freq = Integer.parseInt(parts[1]);
              node[i] = setFreq(freq);
              rootNodes.pqInsert(new SmallNode(i, freq));
              alph[i] = symb;
              i++;
         }
   }
}

NodeType类

public class NodeType{
    private int freq;
    private int father;
    private boolean isLeft;

    public NodeType(){}

    public void isLeft(boolean fact){
        isLeft = fact;
    }
    public boolean isLeft(){
        return isLeft;
    }
    public void setFreq(int fr){
        freq = fr;
    }
    public int getFreq(){
        return freq;
    }
    public void setFather(int fath){
        father = fath;
    }
    public int getFather(){
        return father;
    }
}

1 个答案:

答案 0 :(得分:1)

您的setFreq(int)NodeType类的实例方法。除此之外,我不会返回NodeType对象,因此您无法将其分配给node[i]

您需要做的是创建NodeType对象,使用您需要的值对其进行初始化,然后将其放入数组中。

NodeType node = new NodeType();
node.setFreq( freq );
node[i] = node;