霍夫曼解码EOF字符命中NullPointerException

时间:2013-04-30 02:28:31

标签: java project decoding compression huffman-code

您好我正在解码使用huffman编码压缩的文件。我们使用EOF个字符来表示我们已完成解压缩。每当我为EOF个字符编码时,我就会点击NullPointerException。当我不包括它的检查但它最终得到EOF字符时它工作正常。我不明白我是如何得到NullPointerException的,我很感激能帮助的人。谢谢

public static void decompress(String in, String out)
{
    try 
    {   
        String result = "";
        BinaryNode<Character> pointer = huffTree;
        ArrayList<Character> a = new ArrayList<Character>();
        File outFile = new File(out);
        FileOutputStream decompressedFile = new FileOutputStream(outFile);

        for(char c : decodings.toString().toCharArray())
        {
            if(c == '0')
            {
                pointer = pointer.getLeft();
            }
            else if(c == '1')
            {
                pointer = pointer.getRight();
            }
            if(pointer.isLeaf())
            {
                if(pointer.getElement() == '^')
                {
                    return;
                }
                 decompressedFile.write(pointer.getElement());
                pointer = huffTree;
            }
        }
        decompressedFile.close();
    }
    catch(Exception e)
    {
        System.err.println("Error");
        e.printStackTrace();
    }
}

0 个答案:

没有答案